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.
When you create a macro, you can choose where to save it. You can save macros:
- In a 'global macros file', on a shared computer, where they are available to any other computers that can see that computer.
- In a 'user macros file', on your local computer, where they are available to any project on that computer.
- Within the current project, where they are available to anyone who edits that project on any computer.
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.

If you want to save macros in a 'global macros file', on a shared computer, where they will be available to any other computers that can see the shared computer, or in a 'user macros file', on your local computer, where they will be available to any project on that computer, you must first create the 'global macros file' or 'user macros file', if this has not been done already.
If a global macros file or user macros file has already been created, you must specify the location of the file in Asta Powerproject.
To create a new global macros file or a user 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.
- To create a global macros file, click 'Global macros'; to create a user macros file, click 'User macros'; then click Modify.
- In the dialog that appears, navigate to the location in which to save the file - on a shared computer for a global macros file, or on your local computer for a user macros file - then enter a file name for the macro file, giving it a .VBA extension, and click Open.
- Close the Options dialog.
- Restart Asta Powerproject.
To specify the location of an existing global macros file or user 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.
- To specify the location of a global macros file, click 'Global macros'; to specify the location of a user macros file, click 'User macros'; then click Modify.
- In the dialog that appears, navigate to the location in which the file is located - on a shared computer for a global macros file, or on your local computer for a user macros file - then select the file - it will have a .VBA extension - and click Open.
- Close the Options dialog.
- Restart Asta Powerproject.

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.
To create a macro:
- 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.
- In the left pane, specify where to save the macro:
- Click Global_Macros to save the macro in a 'global macros file', on a shared computer, where they are available to any other computers that can see that computer.
- Click User_Macros to save the macro in a 'user macros file', on your local computer, where they are available to any project on that computer.
- Click VBAProject to save the macro within the current project, where they are available to anyone who edits that project on any computer.
- Select the Module command from the Insert menu. A new module window opens, in which you can write your macro.
- Enter your macro code into the new module window then 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 task'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.

To edit a macro:
- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macros in field, specify whether you want to edit a macro in a global macros file, in a user macros file, or saved in the current project. A list of macros 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.

To delete a macro:
- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macros in field, specify whether you want to delete a macro from a global macros file, from a user macros file, or that is saved in the current project. A list of macros is displayed.
- Select the macro that you want to delete.
- Click Delete to delete the macro.

To run a macro:
- On the View tab, in the Macros group, click the Macros dropdown and select Macros. The Macros dialog appears.
- From the Macros in field, specify whether you want to run a macro from a global macros file, from a user macros file, or that is saved in the current project. A list of macros 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.

To save a project's macros into a .VBA file:
- 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.

To load a project's macros from a .VBA file into a 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.