Initial setup

Now I knew enough to get started writing some serious code. Before doing so, however, I needed to do some initial setup work. To re-create my steps, follow these instructions:

1. Create an empty workbook with five worksheets, named Sheet1, Sheet2, Sheet3, Sheet4, and Sheet5.

2. Move the sheets around randomly so that they aren't in any particular order.

3. Save the workbook as Test.xlsx.

4. Activate the VBE and select the Personal.xlsb project in the Project Window.

If Personal.xlsb doesn't appear in the Project window in the VBE, it means that you've never used the Personal Macro Workbook. To have Excel create this workbook for you, simply record a macro (any macro) and specify the Personal Macro Workbook as the destination for the macro.

5. Insert a new VBA module in Personal.xlsb (choose Insert Module).

6. Create an empty Sub procedure called s ortSheets (see ).

B ti ■ J * i i » ■• ■ i iitHJ, j ..J kl- T?

'jlpum if HWl^'il 111"H illij

1 IIIIWHWH F*MS* ii-jf1!

Figure 9-10: An empty procedure in a module located in the Personal Macro Workbook.

Actually, you can store this macro in any module in the Personal Macro Workbook. However, it's a good idea to keep each macro (or group of related macros) in a separate module. That way, you can easily export the module and import it into a different project later on.

7. Activate Excel. Choose Developer Code Macros to display the Macro dialog box.

8. In the Macro dialog box, select the SortSheets procedure and click the Options button to assign a shortcut key to this macro. The Ctrl+Shift+S key combination is a good choice.

0 0

Post a comment