cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Automate values Excel to Mathcad15 using VBA and return backto excel.

Sakthi-kiran
4-Participant

Automate values Excel to Mathcad15 using VBA and return backto excel.

Hi,

 

I am using Mathcad15 and new to it.

 

i need to feed typically 4 basic values into mathcad and get result back. i have more than 160 sheets to work.

 

Am trying to automate the values logged in excel to feed in Mathcad as different files saving as PDF well.

 

Can anyone suggest or confirm this one is workable.

 

I tried few times but end up with error loading page. Provided the code below.

 

3 REPLIES 3
LucMeekes
23-Emerald III
(To:Sakthi-kiran)

Your excel file has two cells filled:

A1 contains OD

B1 contains 100

 

Your script takes these two values and assigns them to var1 and var2 respectively.

Then it attempts to bind the two values to the real parts of Mathcad variables A and B respectively.

Since Var1's value is OD, which is a string, this swill fail.

Also your script executes a calculation and saves the sheet, but produces no .pdf output...

 

You say you have 160+ sheets to work...

Do they all have the same calculation, and are you attempting to automate executing that same calculation on the basis of 4 variables that take on different values in each of the 160+ sheets? Then it's easier to put the 160+ different sets of 4 variables in a matrix (in Excel if you insist), and have Mathcad calculate the results in one go (and export the results to an excel sheet if necessary).

 

Please explain your scenario better.

Success!
Luc

Hi,

 

Thanks for your response, please find my response as below.

 

Do they all have the same calculation, and are you attempting to automate executing that same calculation on the basis of 4 variables that take on different values in each of the 160+ sheets? - Yes, as below table.

Sakthikiran_0-1724309228192.png

 

Then it's easier to put the 160+ different sets of 4 variables in a matrix (in Excel if you insist), and have Mathcad calculate the results in one go (and export the results to an excel sheet if necessary). - Actually, to maintain some consistency and some constraint within the project i can't modify the Mathcad sheet. Need to represent the individual sheet as PDF.

 

The sample mathcad sheet attached in previous thread. For output Dm can be transfer from Mathcad to excel.

 

Thanks. 

LucMeekes
23-Emerald III
(To:Sakthi-kiran)

Here's another item to be aware of:

Your example sheet defines values for OD, Tass, Hd and WD.

E.g. the very first line in the example worksheet is:

OD := 86 mm

 

Your script uses the SetValue method when assigning values to variables in the example worksheet. The SetValue method assigns the value to the named variable as if it was assigned BEFORE the start of the mathcad worksheet. So every assignment you do in the worksheet will overwrite the value you set with the SetValue method.

In practice: if you use SetValue to set OD to 100 (Note that you cannot set the unit of the value, so OD takes on the value of 100, unitless), the very first thing your worksheet will do is change the value of OD to 86 mm, because that is the first thing it'll do after start, and calculate the results with that value.

This means that your approach with the script (if you get it to work) will always cause the very same result in your worksheet, unless you change the worksheet and take out the assignments to the variables you intend to set via the SetValue method.

 

Success!
Luc

Announcements

Top Tags