In Excel, execute an embedded .exe object

I pasted an object in Excel. This object is an exe (console application).

I can call the application by double-clicking on it. However, I need to call it with parameters (namely, the path to the document file that it is called). How can I call this exe with parameters?

+4
source share
2 answers

If you are importing an EXE file into Excel, follow these steps:

  • Paste - Object
  • Select tab: Create from file
  • View exe file
  • Check "Display as Icon"

then you can write a VBA / macro routine (I used a rectangular shape object to execute the macro by clicking on 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
+2

, . -. .

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
+3

All Articles