Editing Macros






Editing Macros

As handy as the Capture_GIF_Image macro is to use, 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. Because the intent of the macro is to capture 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.

Tip 

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 in which 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 and enhance the macro you recorded in the previous exercise and then run it.

1. On the Tools menu, point to Macro, and then click Macros.

2. Under Macro name, click Parnell Aerospace Promo 17.mpp! Capture_GIF_Image, and then click the Edit button.

Project loads the module that contains the macro in the Visual Basic Editor.

Image from book

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.

3. Click at the beginning of the line, ViewApply Name:=“&Gantt Chart” and press Image from book.

4. Click in the new line you just created, press Image from book, and type Application.Alerts False

This line of code will suppress the prompt you received when running the macro and accept the default option of replacing the existing GIF image file with the same name.

Image from book
Tip 

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.

5. In the line that begins with EditCopyPicture, select the date and time “4/24/08 12:00 AM” (including the quotation marks) that follows FromDate:=, and type ActiveProject.ProjectStart

Note that the specific date you see might not be 4/24/08.

This VBA code describes the project start date of the active project.

Image from book

This causes the macro to get the current start date of the active project for the GIF image that the macro creates.

6. In the same line, select the date and time “6/15/08 12:00 AM” (including the quotation marks) that follows ToDate:=, and type ActiveProject.ProjectFinish

Again, note that the specific date you see might not be 6/15/08.

Image from book

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.

Next, you’ll add new macro capabilities while in the VBA Editor.

7. Click at the beginning of the line EditCopyPicture, and press Image from book.

8. Click in the new line you just created, press Image from book, and type FilterApply Name:=“Incomplete Tasks”

This line of code will apply the Incomplete Tasks filter to the current view.

9. Click at the beginning of the line ZoomTimescale Reset:=True, and press Image from book.

10. Click in the new line you just created, press Image from book, and type FilterApply:=“All Tasks”

This line of code will remove the Incomplete Tasks filter to the current view.

Image from book

11. 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 first you’ll make some changes to the project plan.

12. On the Project menu, click Project Information.

The Project Information dialog box appears.

Image from book

Note the current start and finish dates: 4/28/08 and 6/10/08.

13. In the Start date box, type or select 5/5/08, 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 change to the plan. You’ll record some progress on tasks.

14. Click the name of task 1, Transfer soundtrack to mag. stock.

15. On the Tools menu, point to Tracking, and then click Update Tasks.

The Update Tasks dialog box appears.

16. In the Actual dur field, type 20d, and then click OK.

Next, you’ll record partial progress on task 2.

17. Click the name of task 2, Record music.

18. On the Tools menu, point to Tracking, and then click Update Tasks.

The Update Tasks dialog box appears.

19. In the Actual dur field, type 5d, and then click OK.

Image from book

Now you are ready to rerun the macro.

20. On the Tools menu, point to Macro, and then select Macros.

The Macros dialog box appears.

21. In the Macro name box, click Parnell Aerospace Promo 17.mpp! Capture_GIF_ Image, 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 GIF image in your image application.

22. In Windows Explorer, navigate to the Chapter 17 Customizing folder, and double-click the Parnell Aerospace Promo 17 GIF image file to open it in your image application.

The GIF image appears in your image application.

Image from book

The updated screenshot includes the updated project start and finish dates, and displays only incomplete tasks (note that task 1, which is now completed, does not appear). Now you can run the macro as frequently as needed to capture the most up-to-date information.

23. Close your image viewing application, and then switch back to the Parnell Aerospace Promo 17 project plan in Project.

Here are some additional tips for working with VBA macros in Project.

  • 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.

  • While working in a module, you can get help on specific items such as objects, properties, and methods. Click a word, and then press the F1 key.

  • To close the Microsoft Visual Basic window and return to Project, on the File menu, click Close and Return to Microsoft Project.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows