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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With