Running an executable with dependencies from a network folder

K

kilter

I have an excel 2010 workbook located in a network directory and
a .exe program in the same directory, along with a number of its
dependencies (data files). I'd like to run the exe program from within
a VBA subroutine using a shell command. Current code is as follows

Code:
Sub RunModel()


ReturnValue = Shell("model.exe")
MsgBox ReturnValue


End Sub

This fails as I need to change directories to the network drive and
set the current working directory to ActiveWorkbook.Path, so the shell
command can find the exe file which in turn can find its dependencies.

Not sure how to do this in a way the shell command understands.

Any suggestions gratefully received.
 
K

kilter

This opens notepad...

Dim ProcID As Variant
ProcID = Shell("C:\Windows\system32\notepad.exe", vbNormalFocus)
--
Jim Cone
Portland, Oregon USAhttp://www.mediafire.com/PrimitiveSoftware
(Extras for Excel:  Date picker, Clean Data, Classic Menu ...)

"kilter" <[email protected]>
wrote in message





I have an excel 2010 workbook located in a network directory and
a .exe program in the same directory, along with a number of its
dependencies (data files). I'd like to run the exe program from within
a VBA subroutine using a shell command. Current code is as follows
Code:
[/QUOTE]

Sub RunModel()[/QUOTE]
[QUOTE]
   ReturnValue = Shell("model.exe")
   MsgBox ReturnValue[/QUOTE]
[QUOTE]
End Sub [QUOTE]

This fails as I need to change directories to the network drive and
set the current working directory to ActiveWorkbook.Path, so the shell
command can find the exe file which in turn can find its dependencies.
Not sure how to do this in a way the shell command understands.
Any suggestions gratefully received.

Thanks Jim,

The problem is to do with setting the current directory in the Shell
environment correctly. If I was running this from the command line, I
would just have to change to the network drive, cd to the correct
directory and run the program. I would like to avoid hard wiring the
drive and directory in my VBA, but instead pick this info up from
ActiveWorkbook.Path, or by some other means such that the shell
command executes looking at the correct drive and pointing to the same
path as ActiveWorkbook.Path. Just not sure how to specify that. I can
specify

ChDir (ActiveWorkbook.Path)

but the Shell environment will still be pointing to the C: drive.

I guess the question is how to extract drive info from
ActiveWorkbook.Path, or by other means.

Many thanks
 
G

GS

kilter submitted this idea :
This opens notepad...

Dim ProcID As Variant
ProcID = Shell("C:\Windows\system32\notepad.exe", vbNormalFocus)
--
Jim Cone
Portland, Oregon USAhttp://www.mediafire.com/PrimitiveSoftware
(Extras for Excel:  Date picker, Clean Data, Classic Menu ...)

"kilter" <[email protected]>
wrote in
message





I have an excel 2010 workbook located in a network directory and
a .exe program in the same directory, along with a number of its
dependencies (data files). I'd like to run the exe program from within
a VBA subroutine using a shell command. Current code is as follows
Code:
[/QUOTE]
[QUOTE]
Sub RunModel()[/QUOTE]
[QUOTE]
   ReturnValue = Shell("model.exe")
   MsgBox ReturnValue[/QUOTE]
[QUOTE]
End Sub [QUOTE]

This fails as I need to change directories to the network drive and
set the current working directory to ActiveWorkbook.Path, so the shell
command can find the exe file which in turn can find its dependencies.
Not sure how to do this in a way the shell command understands.
Any suggestions gratefully received.

Thanks Jim,

The problem is to do with setting the current directory in the Shell
environment correctly. If I was running this from the command line, I
would just have to change to the network drive, cd to the correct
directory and run the program. I would like to avoid hard wiring the
drive and directory in my VBA, but instead pick this info up from
ActiveWorkbook.Path, or by some other means such that the shell
command executes looking at the correct drive and pointing to the same
path as ActiveWorkbook.Path. Just not sure how to specify that. I can
specify

ChDir (ActiveWorkbook.Path)

but the Shell environment will still be pointing to the C: drive.

I guess the question is how to extract drive info from
ActiveWorkbook.Path, or by other means.

Many thanks[/QUOTE]

Did you try using 'GetOpenFilename' to load the full path and filename
into a variable that you can pass to Shell or ShellExecute?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
K

kilter

kilter submitted this idea :








This opens notepad...
Dim ProcID As Variant
ProcID = Shell("C:\Windows\system32\notepad.exe", vbNormalFocus)
--
Jim Cone
Portland, Oregon USAhttp://www.mediafire.com/PrimitiveSoftware
(Extras for Excel:  Date picker, Clean Data, Classic Menu ...)
"kilter" <[email protected]>
wrote in
message
I have an excel 2010 workbook located in a network directory and
a .exe program in the same directory, along with a number of its
dependencies (data files). I'd like to run the exe program from within
a VBA subroutine using a shell command. Current code is as follows
Code:
Sub RunModel() 
   ReturnValue = Shell("model.exe")
   MsgBox ReturnValue 
End Sub
This fails as I need to change directories to the network drive and
set the current working directory to ActiveWorkbook.Path, so the shell
command can find the exe file which in turn can find its dependencies..
Not sure how to do this in a way the shell command understands.
Any suggestions gratefully received.
Thanks Jim,
The problem is to do with setting the current directory in the Shell
environment correctly. If I was running this from the command line, I
would just have to change to the network drive, cd to the correct
directory and run the program. I would like to avoid hard wiring the
drive and directory in my VBA, but instead pick this info up from
ActiveWorkbook.Path, or by some other means such that the shell
command executes looking at the correct drive and pointing to the same
path as ActiveWorkbook.Path. Just not sure how to specify that. I can
specify
ChDir (ActiveWorkbook.Path)
but the Shell environment will still be pointing to the C: drive.
I guess the question is how to extract drive info from
ActiveWorkbook.Path, or by other means.
Many thanks

Did you try using 'GetOpenFilename' to load the full path and filename
into a variable that you can pass to Shell or ShellExecute?

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion

I think I've solved this by extracting the required info from the
string returned by ActiveWorkbook.Path

Sub RunModel()

wkbookdir = ActiveWorkbook.Path

ndrive = Left(wkbookdir, 2)

ChDrive (ndrive)

ChDir (ActiveWorkbook.Path)

ReturnValue = Shell("model.exe",1)

End Sub

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top