Reputation: 6531
I have inserted an object into Excel. This object is an exe (a console application).
I can call the application by double clicking on it. However, I need to call it with parameters (namely the file path of the document it is being called by). How do I call this exe with parameters?
Upvotes: 5
Views: 8954
Reputation: 464
The OP asked for a way of including parameters, which doesn't seem to be possible with the accepted solution. I implemented this a different way. This code extracts the file to the workbook's directory and then executes it.
Sub saveAndRunFileExample()
ActiveSheet.OLEObjects(1).Copy
CreateObject("Shell.Application").Namespace(ActiveWorkbook.Path).Self.InvokeVerb "Paste"
Call Shell(ActiveWorkbook.Path & "\example.exe --parameter", vbNormalFocus)
End Sub
Upvotes: 4
Reputation: 2517
If you import .exe to Excel with these steps:
then you can write VBA subroutine/macro like (I used rectangle shaped object to execute macro by clicking it):
Sub RoundedRectangle1_Click()
Dim ws As Worksheet
Dim oo As OLEObject
Set ws = Sheets("Sheet1")
Set oo = ws.OLEObjects("Object 1")
oo.Verb xlVerbPrimary
End Sub
Upvotes: 1