windowsvbaexcelexcel-2003

Embed EXE file in the Excel file


I use:

retVal = Shell("program.EXE " & filename, vbNormalFocus)

To execute a program need for my excel spreadsheet.

Is it possible to embed the EXE file in the excel file itself?

And how would I execute it then?

Ideias:

1 - Some kind of a bin2str function to turn binary to string (so I can store it in the program as a variable and a str2bin (the oposite)

2 - I read something about OLE Control (that you can embed it there), but I really don't know where to start on this one


Solution

  • Here's an outline solution that avoids OLE:

    1. Create a hidden worksheet.
    2. Use a base 64 encoded to convert the exe to text.
    3. Store that text in worksheet cells on the hidden worksheet. Since there is a limit on the number of characters in a cell (32,767) you will need to break the string into chunks.

    Obviously you'll need to reverse this procedure when you want to save and execute the exe file.