Assembling the PiecesYou have all the subordinate task macros ready for carrying out your complex monthly project:
Each piece is prepared and tested. Now you get to put them all together. Record a Macro that Runs Other Macros The easiest way to glue macros together is to record a macro that runs other macros. Record Macro
Now you can look at what you created. Click the Run Macro button, select the MonthlyProject macro, and click Edit. After deleting the standard comments, here's what the macro to run other macros looks like: Sub MonthlyProject() Application.Run Chapter02.xls!ImportFile" Application.Run Chapter02.xls!FillLabels" Application.Run Chapter02.xls!AddDates" Application.Run Chapter02.xls!AppendDatabase" Application.Run Chapter02.xls!DeleteSheet" End Sub The MonthlyProject macro runs each of the subordinate macros in turn. The subordinate macros are known as subroutines. (By the way, this is the reason you start macros with the word Sub, so that you can turn them into subroutines simply by running them from another macro.) Simplify the Subroutine Statements The statement that the macro recorder creates for running a subroutine is somewhat unwieldy. You can simplify the statement, making it easier to read and faster to run.
You now have an automated process for importing each new month's data. You've worked hard and deserve a rest. Take the rest of the day off. |