Find Program Using VBA in Excel (1 Viewer)

tmyers

Well-known member
Local time
Yesterday, 21:37
Joined
Sep 8, 2020
Messages
1,090
Is there a method using VBA to track down a programs file path? I found some examples in C# but have not been able to find anything in VBA to give me guidance on it.

What I am trying to do is rather than hardcode the file path for Acrobat, I would like to find it via VBA in case the next person who happens to use the file does not have it installed in the same location as myself (such as their D drive rather than C). I am doing a decent bit of interaction with Acrobat, so if the path ends up being different, nothing will work hence the problem of hard coding it :). Thanks in advance!
 

KitaYama

Well-known member
Local time
Today, 10:37
Joined
Jan 6, 2022
Messages
1,552
Are you trying to find the installed path of an application or the path of a specific file?

The path of all installed applications can be found in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\

You can read the registry if you need to find the path to any application.

Edit : How to read registry

 
Last edited:

tmyers

Well-known member
Local time
Yesterday, 21:37
Joined
Sep 8, 2020
Messages
1,090
The installed path of an application. In this instance I am trying to find Acrobat so I can launch the .exe file to start messing with PDF's.
 

KitaYama

Well-known member
Local time
Today, 10:37
Joined
Jan 6, 2022
Messages
1,552
The installed path of an application. In this instance I am trying to find Acrobat so I can launch the .exe file to start messing with PDF's.
You have to check for the value in this key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe
 

KitaYama

Well-known member
Local time
Today, 10:37
Joined
Jan 6, 2022
Messages
1,552
If you want to open a pdf you don't need to know the path to the exe file
you simply can run the following. Windows takes care of the location of the exe.

Code:
Dim Ret as variant
strPath="C:\myfile.pdf"
Ret=Shell("rundll32.exe url.dll,FileProtocolHandler " & strPath, vbMaximizedFocus)
 
Last edited:

tmyers

Well-known member
Local time
Yesterday, 21:37
Joined
Sep 8, 2020
Messages
1,090
I cant seem to get either webpages you linked to load :(

Edit:
I will give the Shell way a go as that seems much simpler lol
 

tmyers

Well-known member
Local time
Yesterday, 21:37
Joined
Sep 8, 2020
Messages
1,090
Thank you Kita!
I will work with this and report back if I run into any problems.
 

Users who are viewing this thread

Top Bottom