Help Edit the code Open the program by the link

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone. I need help how to fix the below code to open Google Drive program when the path changes frequently
C:\Program Files\Google\Drive File Stream and GoogleDriveFS.exe : Stand still
50.0.11.0 : Usually change

I want to fix it, if I change the path at 50.0.11.0 , the code will still run . Or can you advise me a code that opens a program regardless of the path. Thank you very much


1631090488958.png


VBA Code:
Sub openprogram()
On Error Resume Next
   Dim Shex As Object
   Set Shex = CreateObject("Shell.Application")
   tgtfile = "C:\Program Files\Google\Drive File Stream\50.0.11.0\GoogleDriveFS.exe" ' address
   Shex.Open (tgtfile)
   MsgBox ("run")
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
why is it changing? what is changing it?
 
Upvote 0
There is a similar discussion here:
Code to open a program by name
This will at least show you how to capture the cmd output.
There are more discussions on this topic everywhere.
You can use this CMD to get the actual path to the file:
Bash:
dir "C:\Program Files\Google\Drive File Stream\*GoogleDriveFS.exe" /s /b /a:-d
 
Upvote 0
There is a similar discussion here:
Code to open a program by name
This will at least show you how to capture the cmd output.
There are more discussions on this topic everywhere.
You can use this CMD to get the actual path to the file:
Bash:
dir "C:\Program Files\Google\Drive File Stream\*GoogleDriveFS.exe" /s /b /a:-d
I would like to thank you. But I want the code to run completely automatically, no need to run CMD run the code first
can you provide me complete VBA code to open 1 program by program name regardless of path. Thanks
 
Upvote 0
see if this works:
VBA Code:
Sub test_a()
Dim exec
exec = Split(CreateObject("WScript.Shell").exec("CMD /C dir ""C:\Program Files\Google\Drive File Stream\*GoogleDriveFS.exe"" /s /b /a:-d").StdOut.ReadAll, vbCrLf)(0)
exec = Shell(exec, vbNormalFocus)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top