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 Sheetl, 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.xls.
4. Activate the VBE and select the Personal.xls project in the Project Window.
If Personal.xls doesn't appear in the Project window in the VBE, this 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 (choose the Insert ^ Module command).
6. Create an empty procedure called SortSheets (see Figure 9-9).
Actually, you can store this macro in any module in the Personal Macro Workbook. However, it's a good idea to keep each macro 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 the Tools ^ Macro ^ Macros command (Options button) to assign a shortcut key to this macro. The Ctrl+Shift+S key combination is a good choice.
Was this article helpful?