C++, VBA and Shell comand problem

Hi,
I know this is sort of off topic but I have not been able to find a answer anywere I have looked.

I have written a little program called SSTe.exe. When executed it opens a file called SSTe.start that resides in the same folder. In this file is the actual file name with the data needed for the calculations. If the SSTe.exe is started by double clicking it always works (thus far at least ;-)

Since I am not going to be the only person working with the program I wanted to make the generation of the input data a little more convenient. To that end I have created a Excel file that contains all the data and creates the needed input file and changes SSTe.start accordingly. So far this all works fine and I can MANUALLY execute the SSTe.exe with no problem.

I would however like that the macro used to generate these files also starts the simulation. To that end I have found the following VBA command that works sort of fine:
1
2
3
4
5
    Dim SSTe
    Dim relativePath As String
    relativePath = ThisWorkbook.Path

    SSTe = Shell(relativePath & "\SSTe.exe", vbNormalFocus)

In any case SSTe.exe starts but then fails to open SSTe.start. For some, even stranger reasons, it did work for about an hour last night, but this morning that was history.
Do you have any suggestions what could be the problem?
Thanks for any comments, hint, suggestion or, best of all, solutions
BenBehr

P.S.
The SSTe.exe looks for the SSTe.start in the same directory as it resides itself.
Last edited on
You need to set the working directory. See if Shell() allows you to set it. If not, you'll have to look for a different method to run it or maybe pass the location of the .start file via the command line.
Get full path for SSTe.exe itself with GetModuleFileName(), then use PathRemoveFileSpec() to find real directory where SSTe.start resides.

You said that SSTe.exe is written by you, so you should do it without any problems.
Thanks webJose,

this actually got me to a working solution. Even though it requires a bit of extra.

The code now looks like this:
1
2
3
4
5
    Dim SSTe
    Dim relativePath As String
    relativePath = ThisWorkbook.Path

    SSTe = Shell(relativePath & "\SSTe.bat" &relativePath, vbNormalFocus)


Where the &relativePath is passed on to the SSTe.bat file that in turn runs the SSTe.exe located in that directory.

The full solution fot the VBA problem can be found at the link below. (I hope it is ok that I am posting it here since it is not realy a c++ issue but I would like to relay close the case properly)

VBA Solution
http://stackoverflow.com/questions/9403341/running-a-batch-file-in-a-given-directory-using-vba
Topic archived. No new replies allowed.