Reputation: 39
Right, situation first:
I would like to be able to issue some commands which carry out all these operations at the click of a button. So far I have this:
Public Sub Execute_Mathcad()
Dim x As Variant
Dim Path As String
Dim File As String
'save application in current form (should be up to date)
ThisWorkbook.Save
'pause vb script so mathcad can run normally
Application.Wait (Now + TimeValue("0:00:20"))
'open the external program
Path = "C:\Program Files (x86)\Mathcad\Mathcad 15\mathcad.exe"
File = "C:\Users\blah\blah.xmcd"
x = Shell(Path + " " + File, vbNormalFocus)
'issue CTRL+F9 in active program - can the keystroke be issued through windows directly (this solves and saves the MathCad program)
SendKeys ("^{F9}")
'exit mathcad using VBA command
'import results (I have code for this)
End Sub
The main problem for me seems to be how to pause excel and allow the external program to run. It cannot run whilst excel is open since it has to pull data from the workbook for some reason?
Secondly, how can you issue a keyboard shortcut in an external program (e.g. CTRL+F9)
Thanks!
Upvotes: 2
Views: 8001
Reputation: 12728
Write a bat or vbs file that will launch MathCad, Close Excel, and then relaunch Excel and execute the result import. Call the file from a shell command much like you're currently opening MathLab.
Upvotes: 1