You know how maybe once a year you have one of those coding experiences that make you literally shout for joy? This thread gave me one.
I read and tried the info from maybe 100 URL's on Shell, ShellExecuteA, ShellExecuteExecute to no avail. I used a manual work around for years until I herein found mtheriault's solution to set Excel to admin mode. I was so thankful for this long-sought solution that I joined the forum just to possibly assist others googling similar keywords to mine to find help on this topic.
I was using the following type of code (mind you this is a cut out from 100's of code lines across 10 subs and 6 functions) and it worked fine for calling a program at C:\Jts\tws.exe but not for the below illustrated "C:\Program Files (x86)\Value Line Publishing\Value Line Investment Survey\VLIS.exe". I suspected it had something to do with the 32 vs 64 bit nature of the programs, but now doubt this has anything to do with it.
I would activate the desired program (TWS or VLIS) so as to apply an AutoHotKey (AHK) script, however the AHK script required that I set the VLIS.exe to run as Admin (Admin mode not required for TWS, hence my remaining slight suspicion of 32 vs 64 bit factoring in). Once I did set VLIS to Admin, AHK ran fine but shell wouldn't. I only code once a week as a hobby and so did not connect the VLIS.exe Admin setting to the shell failure and based on the error message (Run-Time error '5': Invalid procedure call or argument) I thought the shell failure was based elsewhere. Naturally any documentation I looked at for a solution did not touch on mtheriault's method.
Frankly, I'm in awe of how mtheriault happened figured this out and very grateful to norie for re-opening the thread, mtheriault for coming back and sharing his solution, and norie again for encouraging such good solution-sharing practices, all of which brought me to contribute my 2 cents here at OzGrid.com, for which I am also thankful.
Public vPID As Variant
Public Sub Open_VL_and_Get_PID()
vPID = shell("C:\Program Files (x86)\Value Line Publishing\Value Line Investment Survey\VLIS.exe", vbMaximizedFocus)
waitOnReturn = True 'Waits for shell to finish before returning to VBA
End Sub
Public Sub Activate_VL_by_PID_and_Run_AHK()
AppActivate (vPID)
<VBA to run AHK goes here>
End Sub
Display More