I want to launch an external .exe program from my Visual Basic Application, but it needs to be in the same directory, that could change multiple times. Is there anyway of the application finding out the address itself and then finding the file? like... Process.Start(';$GetDirectory$/Applicatio鈥? except ofcourse, $GetDirectory$ being the command that makes it find the directory.How do you launch an exe file in VB without using its full address for like files that are in the same folder?
-----
Well it's harder to do this in VBA. In VB you could just use App.Path. That doesn't work in VBA. There's a few things you could try. If you're using Access, try CurrentProject.Path. Or if you're using Excel, try ThisWorkbook.Path. If you're using Word try ActiveDocument.Path.
For different applications there's a different object you have to use.
Hope this helps!
-----
I think I misread your question. If it's just a normal VB application, just use App.Path to get the application path. There is one trick though. If the path is ';C:'; there will be no ';\';, unlike other paths (e.g. ';C:\Program Files\';). To compensate for this, I usually create another variable (call it AppPath for instance), which I set as follows:
Dim AppPath as String
AppPath = App.Path
if right(AppPath, 1) %26lt;%26gt; ';\'; then
AppPath = AppPath %26amp; ';\';
end if
AppPath can then be used in place of your $GetDirectory$ for instance:
Process.Start(AppPath %26amp; ';programname.exe';)How do you launch an exe file in VB without using its full address for like files that are in the same folder?
Finding it somewhere on the same computer, with no restraints?
Find all the drives. Start with the first one and walk the directory structure looking for the fgile. (There's no guarantee that the file you find is actually the one you want. Someone else may have created a file with the same name.)
You can find directory walking code all over the internet. Karen's replicator has good code in VB6.
use ';App.Path'; and concatenate it with the application name to run
for example
Process.Start( App.Path %26amp; ';Application1.exe'; )
hope this helps.
No comments:
Post a Comment