As handy as the Save_As_Web_Page macro is, it can be improved. Remember that when you ran it in the previous exercise, you had to confirm that Project should overwrite the existing GIF image and HTML files. Because the intent of the macro is to publish the most current information, you would always want to overwrite the older information. You can change the macro code directly to accomplish this. The macro code resides in a VBA module, and you work with the code in the Visual Basic Environment.
The VBA language and Visual Basic Environment are standard in many of the programs in the Microsoft Office System (including Project). Although the specific details of each program differ, the general way you use VBA in each is the same. VBA automation is a powerful tool you can master, and that knowledge can be used in many Microsoft programs.
In this exercise, you work in the Visual Basic Editor to fine-tune the macro you recorded in the previous exercise and then run it.
On the Tools menu, point to Macro, and then click Macros.
Under Macro name, click Parnell Aerospace Promo 18.mpp!Save_As_Web_Page, and then click the Edit button.
Project loads the module that contains the macro in the Visual Basic Editor. Your screen should look similar to the following illustration:
A full explanation of the VBA language is beyond the scope of this book, but we can walk you through some steps to change the behavior of the previously recorded macro. You might also recognize some of the actions that you recorded earlier by the names used in the VBA code.
Click at the beginning of the line ViewApply Name:="&Gantt Chart", and press [Enter].
Click in the new line you just created, press [Tab], and type Application.Alerts False
Your screen should look similar to the following illustration:
This will prevent the two prompts you received when running the macro and accept the default option of replacing the existing files with the same name.
Note that as you were typing, selection boxes and ScreenTips might have appeared. The Visual Basic Editor uses such tools and feedback to help you enter text in a module correctly.
In the line that begins with EditCopyPicture, select the text that follows FromDate:= text "4/14/05 12:00 AM" (including the quotation marks), and type ActiveProject.ProjectStart.
Note that the specific date you see might not be 4/14/05.
This VBA code describes the project start date of the active project. Your screen should look similar to the following illustration:
This causes the macro to get the current start date of the active project for the GIF image the macro creates.
In the same row, select the text that follows ToDate:= text "6/5/05 12:00 PM" (including the quotation marks), and type ActiveProject.ProjectFinish
Again, note that the specific date you see might not be 6/5/05. Your screen should look similar to the following illustration:
This causes the macro to get the current finish date of the active project for the GIF image that the macro creates. Now if the project plan’s start or finish date changes, the date range for the GIF image will change as well.
On the File menu in the Visual Basic Editor, click Close and Return to Microsoft Project.
The Visual Basic Editor closes, and you return to the Parnell plan.
You could run the updated macro now, but to test whether it really uses the most current project start and finish dates, you’ll change the start date of the project plan.
On the Project menu, click Project Information.
The Project Information dialog box appears. Your screen should look similar to the following illustration:
Note the current start and finish dates: 4/18/05 and 5/31/05.
In the Start date box, type or select 4/25/05, and then click OK to close the Project Information dialog box.
Project reschedules the start (and all subsequent dates) of the project plan. Before you rerun the macro, however, you’ll make one more major change to the plan. You’ll change the duration of task 1 from 14 days to 7.
In the Duration field for task 1, Transfer soundtrack to mag. stock, type or select 7d, and then press [Enter].
Project adjusts the duration for task 1 and reschedules all successor tasks. Your screen should look similar to the following illustration:
Now you are ready to rerun the macro.
On the Tools menu, point to Macro, and then select Macros.
The Macros dialog box appears.
In the Macro name box, click Parnell Aerospace Promo 18.mpp!Save_As_Web_Page, and then click Run.
The macro runs, and this time you are not prompted to overwrite the previously saved files.
To verify that the macro ran correctly, you’ll view the updated Web page in your browser.
Switch back to your browser. The previously viewed project plan should still be visible.
Click the Refresh button to reload the most recently saved HTML file and related GIF image.
The updated HTML file and related GIF image appear in your browser. Your screen should look similar to the following illustration:
Now you can run the macro as frequently as needed to keep the most up-to-date information published.
VBA is a rich and well-documented programming language. If you would like to take a closer look at VBA in Project, on the Tools menu, click Macro, and then click Visual Basic Editor. In the Microsoft Visual Basic window, on the Help menu, click Microsoft Visual Basic Help. To get help on specific items in a module such as objects, properties, and methods, click a word, and then press the [F1] key. To return to Project, on the File menu, click Close and Return to Microsoft Project.