Let's say you need to run a Mathcad Prime worksheet without user intervention and at a particular time of the day. Without the ability to schedule such tasks, you’d have to remind yourself to do so manually, and potentially run the risk of forgetting entirely.
Good news: the combination of Windows 7’s task scheduling feature and the power of Mathcad Prime enables users to delay the processing of certain tasks.
Task scheduling is particularly beneficial when it comes to reporting. For example, if you need a particular Excel-based report generated overnight, and computations carried out on the extracted data for review first thing in the morning, Mathcad Prime and Windows 7 will let you do just that.
In this post, we’d like to show you how to schedule tasks in Mathcad, thanks to an often forgotten feature within Microsoft Windows.
Step 1: Create the worksheet
Firstly, you need to create a Mathcad Prime worksheet that is capable of reading an external file generated on schedule. It also needs to undertake the computation and write the results back into the same Excel sheet.
Here’s the equation required to read the values from the Excel file:
…and the equation Mathcad uses to compute the values and write them back into Excel:
Step 2: The Visual Basic script
You will need a Visual Basic (VB) script that the Windows Task Scheduler can access and run. An example of the completed VB script written by PTC and relevant to the example schedule described in this post can be downloaded here.
Once you’ve downloaded the sample script, you can make it work for other Excel worksheets very easily. To do so, simply open the script file using Notepad, and give it a new name.
The script walks itself through the following process:
- Launches Mathcad Prime;
- loads the previously created worksheet;
- executes the worksheet;
- waits for one second before closing the worksheet and Mathcad Prime.
Step 3: Create the assignment in Windows 7 Task Scheduler
Once you have created the Mathcad worksheet and edited the VB script provided above, it’s time to tell the Windows 7 Task Scheduler that a new assignment is required.
To do so, follow these simple steps:
- Head to the Control Panel, choose Administrative Tools and double-click the Task Schedule icon. The Task Scheduler should appear:
- In the right-hand Actions panel, click Create Basic Task… and give it a name and description:
- It’s time to set the Trigger frequency. Windows 7 offers a range of options from daily to more dynamic triggers such as when the computer is turned on or when a specific event is logged:
- Give your task a start time. You can set this right down to the second if you wish, and configure it to recur on a specific number of days, if required:
- Now, you can load the VB script created previously that will run the Mathcad worksheet, compute the data you require and send it back into Excel. To do so, click Action, then choose Start a Program. You’ll then be able to browse your computer’s hard disk for the script itself:
If you follow the simple steps above, you’ll have fully prepared and configured a scheduled task for your Mathcad report. That means no more manual reporting, and the data you require delivered to your hard drive automatically, just when you need it.