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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Excel as a I/O for Mathcad calculations

ThomasH-disable
1-Newbie

Excel as a I/O for Mathcad calculations

Good evening all,

I've been plugging through this problem for a long time now, yet to find a solution that's reliable and workable. Hopefully someone here can throw me a life line.

I'm moving some calculations to Mathcad as it's better for QA as apposed to Excel. However as far as creating in Mathcad goes it's got a way to go. So what I need to do is use excel as a data input and output device where the layout can be suited, leaving Mathcad to do all the hard work. Ideally I'd write the Mathcad file and then lock it away so it can't be edited.

It would take some VB coding but I've dead ended on it and have lost the will.

Does anyone knows how to simply
1) take a value (one cell or a range) from Mathcad
2) run it through a simple calc (e.g. out=in*2, not important)
3) fire the results back to excel in a set cell(s) in the same sheet.

The Developers Help brags about how it's possible but then doesn't actually help me develop it.

Kindest Regards, Thomas.
6 REPLIES 6

Which one do you want as the driving piece of software, Excel or Mathcad? If it's Mathcad, do you want to reference an Excel file on disk, or have an Excel object embedded in the Mathcad document? All of these are possible.

Richard

Try to modify the macros in the attached at

http://collab.mathsoft.com/read?105898,11

Regards. Alvaro.

You need to have the Mathcad add-on for Excel, for starters. That will allow Excel to interface with an embedded Mathcad sheet. Once the add-on is installed in Excel, there should be an added toolbar that allows you to insert a Mathcad component within Excel, and it'll have the hooks for input/output of variables.


TTFN,
Eden

Thank for the reply, appreciate your time.

The driving piece of the software would be Excel. With the data in excel being poked to mathcad solved and pushed back to excel.

I've done it the embedded way but I wanted to basically do the same process but remove the embedded mathcad to an external mathcad file which the VB code in excel activates and runs.

Tried DDE, got most of the code but no joy calling the program.
Tried embedding a mathcad OLE with a reference to external mathcad file which gives the solution (albeit unreliably) but this doesn't update automatically.

Here's the code from my DDE attempts if that helps anyone, however the API method would be a better option, or so the DDE haters tell me.

Thanks for your help so far everyone.

Sub McadData()
Dim PokeRange As Object
Dim Channel As Integer
Dim B As Variant

Set PokeRange = Worksheets("Sheet1").Cells(1, 1)
'mathcad = Shell("C:\Program Files\Mathcad\Mathcad 14\mathcad.exe", vbHide)
'Channel = Shell("F:\my documents\1.used daily\MathCAD\DDE method\ref\test.xmcd", vbHide)
Channel = Application.DDEInitiate( _
app:="Mathcad", _
topic:="F:\my documents\1.used daily\MathCAD\DDE method\ref\test.xmcd")
Application.DDEPoke Channel, "A", PokeRange
Application.DDEExecute Channel, "[Calculatedoc()]"
Application.DDEExecute Channel, "[Save()]"
bval = DDERequest(Channel, "B")
DDEPoke Channel, bval, Worksheets("Sheet1").Cells(2, 2)
Application.DDETerminate Channel
End Sub

Take a look at the example here:

http://collab.mathsoft.com/read?108327,11e#108327

Richard

I sort of found a solution, although it wasn't what i ideally wanted.

I basically inserted an OLE object as per normal and on this i put the inputs, a reference to a mathcad file with those input names and an output.

e.g.

in0:=(A, B, C)
Reference:C:\my documents\work\mcadwork.xmcdz
out0:=

This way i set the input of in0 in the macro to the cells i'm using and then set them to letters in the OLE object. These are then used in the equation(s) in the external mathcad file at the referenced location and the answers set to out0, with the macro pasting them into the cells.

Didn't know you could reference a file for just it's equation.

Thanks for your help everyone. I thought i'd post my solution to help close the circle for anyone else.

Regards, Tom
Top Tags