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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Mathcad Excel interfacing

ptc-5053189
1-Newbie

Mathcad Excel interfacing

We have an Excel spreadsheet that has been developed previously over time. We would now like to use this spreadsheet to perform calculations using values obtained from calculations perfomed in Mathcad and then return the value obtained in Excel back to Mathcad without including the Excel as an object into Mathcad as the Excel is maintained by another discipline.

The problem we have is that we can send the data to Excel and read the required information back again, but only if the Excel file is not open. This, however, means that the actual calculations are not performed if the Excel file is not actually opened. We would like to perform this action in a batch process for optimization. Having to manually open Excel to calculate makes this impossible.

Is there a method of automatically refreshing the Excel calculations during such a batch process without atually embedding the object.

2 REPLIES 2

Attached is a file long since copied from the forum, it shows read& write access to an XL sheet.

However, as you indicate, if the file is already open in XL then the routines fail.

The best workaround that I can think of is to create a local (temporary) copy of the original sheet,

run all the calculations that you need and

finally, delete the copy so that any updates to the original file will be applied the next time you run the mathcad sheet.

For ways to copy & delete , try : http://communities.ptc.com/message/228971#228971

regards

Andy

Andy

Thanks. I have not run the file yet, but I am easy with normal reading and writing from and to Excel. The problem is that we want to write to Excel, then Excel needs to do some calculations with the values we passed to Excel and update the Excel sheet. When we then read from Excel again we want to read the new updated values. As I see it this requires Excel to be closed when we read and write, but open to update the spreadsheet. This means that I have to manually open the sheet after writing the info to it in order to update the calculations with the latest values sent to Excel. Thereafter I need to close Excel again before reading the answers back into Mathcad. Looking at your reply this does not seem to be the intent of the example. Doing once is OK, however, we are running multiple batch runs with the model making the manual interaction impossible.

I previously bypassed this problem by embedding the Excel object into Mathcad and sending the values into Excel as inputs and reading them as outputs. However, the Excel in this case is primarily maintained by a third party and therefore we would like not to embed it into Mathcad as to ease the process of interfacing with the latest version of the Excel file at all times. As I have it this does not seem possible though, but I would like your view on it.

Top Tags