Using macros to automate processes
You can use macros to automate repetitive tasks so that you have to spend less time performing these tasks manually. For example, you could use macros to automate:
- The creation of monthly progress reports.
- The adjustment of all your cost and income rates by a specific percentage.
- Rescheduling and resource levelling to take place overnight when nobody is using the system.
- Importing resource details from external databases, such as a payroll system.
You write macros using Visual Basic® (VB) or Visual Basic for Applications (VBA). Visual Basic for Applications is supplied with Asta Powerproject.
Macros are not available in Asta Powerproject SaaS.

You can write a macro from within Asta Powerproject by running Visual Basic Editor and typing commands into it. To run Visual Basic Editor, on the View tab, in the Macros group, click the Macros dropdown and select Visual Basic Editor. The Visual Basic Editor opens as a separate program.
For information about using Visual Basic Editor, refer to its online Help.
When you create a macro, you can choose where to save it. You can save macros:
- On a shared computer where they are available to any clients that can see that computer (globally).
- On the client machine where they are available to any project on that client machine (locally).
- Within a project where they are available to anyone editing that project.
To create a user macros file or a global macros file in which to store macros:
- Open a project within Asta Powerproject.
- Click the File tab, then click Options. The Options dialog appears.
- Click the File Locations tab.
- Select User Macros or Global Macros, depending on whether you want the macros in the file to be available locally or globally, then click Modify.
- Enter a file name for the macro file, giving it a .VBA extension, or select an existing macro file, then click Open. Do not select the existing file called macros.vba.
- Restart Asta Powerproject.
- On the View tab, in the Macros group, click the Macros dropdown and select Visual Basic Editor. The Visual Basic® Editor opens as a separate program.
- If you selected an existing file, you see its contents. If you created a new file, right-click User Macros or Global Macros, depending on the type of file you created, then select the Module command from the Insert menu to create a new module within the file.
- Enter your macro code into the new module and select the Save command from the File menu to save the macro.
When you create or run a macro using Visual Basic rather than the Visual Basic Editor, you do not need to run the Asta Powerproject client first, because Visual Basic invokes a client. If you create or run a macro using Visual Basic and Asta Powerproject OCX, the OCX is the client. The OCX is a Microsoft ActiveX® control; it contains the Asta Powerproject client with no user interface. This means that you could write your own add-on program with a completely different user interface from the Asta Powerproject client. For example, you could write an Asta Powerproject program or you could use the OCX to display live project data on a web site. You can only access the OCX if you have the Developers' Toolkit.

When writing a macro, you must bear in mind the fact that the calculation of business objects takes place on the server in Asta Powerproject, not on the client. For example, if you set the start date of a task, the links relating to the task are recalculated on the server and then notified back out to the clients. Therefore if you move a task and want information on the tasks's links, you have to wait for the notifications to come back from the server.
For this reason, it is essential to call project.WaitforNotificationsProcessing after every update (edit, creation or deletion) of a business object, if you need to access any fields subsequently that are likely to be recalculated after an edit. This applies both to calculated fields on the business object itself and fields on connected objects.

- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macro Scope field, select the module containing the macro that you want to test. A list of the macros within the module is displayed.
- Select the macro that you want to test.
- Select the No Break on Errors check box if you want to skip over any errors in the selected macro and run it through to the end, or clear the check box if you want the macro to be interrupted if an error is encountered.
- Click Step to run through the selected macro step-by-step.
- The selected macro opens in Visual Basic Editor and runs one step at a time, pausing at each instruction and highlighting it before running it. To continue stepping through your macro, click the Step Into button on the Debug toolbar in Visual Basic® Editor, or press F8.
- When you have finished stepping through your macro, close Visual Basic Editor by clicking its Close box. If you have edited the macro, you will be given the opportunity to save your edits before Visual Basic Editor closes.

- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macro Scope field, select the module containing the macro that you want to edit. A list of the macros within the module is displayed.
- Select the macro that you want to edit.
- Click Edit to open the macro in Visual Basic Editor.
- Edit the macro as required.
- When you have finished editing your macro, save your changes and close Visual Basic Editor by clicking its Close box.

- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macro Scope field, select the module containing the macro that you want to delete. A list of the macros within the module is displayed.
- Select the macro that you want to delete.
- Click Delete to delete the macro.

- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macro Scope field, select the module containing the macro that you want to run. A list of the macros within the module is displayed.
- Select the macro that you want to run.
- Click Run to run the macro.
The macro takes over your Asta Powerproject desktop while it is running; you cannot interact with Asta Powerproject until the macro is finished.

- On the View tab, in the Macros group, click the Macros dropdown and select Save Macros.
- Specify a path and enter a file name, with a .VBA extension, for the file into which to save the macros.
- Click Save to save the macros to the specified file.
Once you have saved a project's macros, you can load them into another project.

- On the View tab, in the Macros group, click the Macros dropdown and select Load Macros.
- Select the .VBA file that you want to load.
- Click Open.
The macros in the selected .VBA file are now available for editing and running.