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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Excel to MathCAD and Results Back to Excel

iainmoonie
2-Explorer

Excel to MathCAD and Results Back to Excel

Hi all, I am looking to program a script (presumably VB) that can help automate the assessment of structural members. We have numerous structural members (with various material and geometric input properties), which are subject to varying applied input loading. 

 

I'm looking to create a script that can read the input variables (geometry, loads, properties...) from Excel into a pre-existing MathCAD calculation. The MathCAD calculation uses the input variables to calculate structural member utilisations.

 

I would then like to export the MathCAD calculated utilisations to record them in Excel against the relevant member. 

 

Many thanks in advance - Iain

 

 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:iainmoonie)

Might be feasible.

Have a look at your Mathcad application Help menu, in the section "Accessing Mathcad from within another application" you should find something like:

LM_20180124_Excel-MathCad-Excel.png

 

Success!

Luc

View solution in original post

6 REPLIES 6

Mathcad 15 Prime

Hi Valery I'm using MathCAD 15 and Excel 2016 on works computer so limited access to upgrade/change software

 

Iain

LucMeekes
23-Emerald III
(To:iainmoonie)

Might be feasible.

Have a look at your Mathcad application Help menu, in the section "Accessing Mathcad from within another application" you should find something like:

LM_20180124_Excel-MathCad-Excel.png

 

Success!

Luc

Hi Luc - thanks for the link I've managed to figure out the MathCAD help article and got a rough version of what i want out of it. So thanks for pointing me in this direction!

 

One issue - my VBA script doesn't seem to refresh very well upon re-opening the Excel. I need to double click on the MathCAD OLE object so that the macro runs correctly...no doubt missing something basic.

 

Another thing that was stumping me was the need for real AND imaginary numbers for each input variable...new to all this coding malarky / exact science.

 

I've copied my VBA macro below in case others come up against this (now relatively easy) problem. 

 

Sub UpdateWorksheet()
Dim MathcadObject As Object
Dim outRe1, outIm1, outRe2, outIm2 As Variant
Dim inRe1, inIm1, inRe2, inIm2 As Variant

'Set a reference to the Mathcad object on the sheet
Set MathcadObject = ActiveSheet.OLEObjects(1).Object

'Read in values to be passed from Excel to Mathcad. Only Real Values Required Here
inRe1 = ActiveSheet.Range("I4:I1000").Value
inRe2 = ActiveSheet.Range("k4:k1000").Value

'end the values over to Mathcad, assign them to variable in0,
'recalculate, and read the results from out0 back into Excel
Call MathcadObject.SetComplex("in0", inRe1, inIm1)
Call MathcadObject.SetComplex("in1", inRe2, inIm2)
Call MathcadObject.Recalculate
Call MathcadObject.GetComplex("out0", outRe1, outIm1)
Call MathcadObject.GetComplex("out1", outRe2, outIm2)

' Place the result values into the chosen Excel cells
ActiveSheet.Range("P4:P1000").Value = outRe1
ActiveSheet.Range("R4:R1000").Value = outRe2


End Sub

LucMeekes
23-Emerald III
(To:iainmoonie)

I like smileys in computer code...

 

Luc

Haha don't know what happened there!

 

That's meant to be : P not 😛

 

Also, updated that cropped photo 

Announcements

Top Tags