Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello,
I would like to learn how to use Mathcad Prime 7 Automation API in VBA Excel.
If anyone can share tutorials or examples, that would be great.
The "Code Examples" in PTC Mathcad Help are for different languages, I think.
Like the examples in VB.NET & VBScript, I tried to study them but struggled to understand the syntax and could not see the similarity with VBA Excel syntax (sorry, i am new to programming).
thank you in advance for your help.
Solved! Go to Solution.
Hi,
Some examples for the use of the Prime API are found in the API Guide in help. But I am sure you know that, so pictures below are for the benefit of others
The API Guide has a number of examples but not one for VBA - Excel.
From the guide
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
VBA - Excel is not managed code so needs an Application object.
From the VB-Script example in the API Guide.
__________________________________________________
' Get the Mathcad Prime application object:
Set mathcad = CreateObject("MathcadPrime.Application")
mathcad.Visible = true
mathcad.Activate()
________________________________________________________
This kind of sets the tone for the VBA-Excel syntax. Instead of CreateObject you use New. in VBA-Excel like the guide says.
In PTC University there is an API tutorial. Not sure what language they use for it.
Cheers
Terry
Hi,
API programming is really about exchanging data between Excel and Prime,
It is easier to use READEXCEL and WRITEEXCEL functions to exchange the data between the two softwares.
Cheers
Terry
Hi
https://community.ptc.com/t5/Mathcad/Mathcad-and-Excel-VBA/m-p/785228#M200372
Step 1 In excel sheet, we have let say three values in three cells variable with values such as a is 350, b is 505 and c is 900 and so on (actually I have more than 100 values)
Put the 100 values in 100 contiguous Excel cells so they can be referred to as one matrix of values to transfer to Prime.
Step 2 Excel vba open mathcad using COM or API
Step 3 Excel sent a, b, and c value in mathcad. where many operation are performed such addition, square and many more using these a,b and.
The enclosed spreadsheet has 100 cells with values and the VBA macros and forms shows how to transfer the values either way.
A button on the Excel worksheet shows a form. The form has a Go button. Press Go and Excel opens Mathcad transfers 100 values to Prime. Prime multiplies them all by three. Excel reads the values back and shows them in the form. Be patient as there is a pause time built in.
Step 4 Excel send signal to print mathcad and then close the mathcad worksheet.
Use the VBA commands below to save and close the file. Don't know if VBA can print the Prime file?
WS.Save
MCApp.CloseAll (SaveOption_spSaveChanges)
Hello Terry,
Thank you for this.
On your first reply, i am building an application (like a GUI) in VBA Excel that's why i need it to communicate with MatchPrime 7. This GUI will accept user inputs and pass them to Mathcad....Mathcad computes and pass back the results. And some post processing of the results, like plotting charts, will be done.
And on your second reply, in the example RunningMathcad.xlsm, i can see this syntax for launching Mathcad:
Set MCApp = New Ptc_MathcadPrime_Automation.Application
MCApp.Visible = True
However, in the Mathcad help under API Guide, it says this:
But with this, i get a compile error: User-defined type not define, so it's wrong.
Pardon my ignorance, but how did you know the correct syntax?
Could you point me to a resource or tutorial that will teach me about the syntax of at least the most common Mathcad Prime objects?
The Object browser in VBA Excel does not show the syntax or examples.
thank you, again.
Hi,
Some examples for the use of the Prime API are found in the API Guide in help. But I am sure you know that, so pictures below are for the benefit of others
The API Guide has a number of examples but not one for VBA - Excel.
From the guide
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
VBA - Excel is not managed code so needs an Application object.
From the VB-Script example in the API Guide.
__________________________________________________
' Get the Mathcad Prime application object:
Set mathcad = CreateObject("MathcadPrime.Application")
mathcad.Visible = true
mathcad.Activate()
________________________________________________________
This kind of sets the tone for the VBA-Excel syntax. Instead of CreateObject you use New. in VBA-Excel like the guide says.
In PTC University there is an API tutorial. Not sure what language they use for it.
Cheers
Terry