Set focus to application opened when using ShellExecute

I use the following line of code as part of a public sub routine to open various types of files from within Access:
 iRet = ShellExecute(Forms("frmActivity").hWnd, "open", sDocFileNamePath, "", "", nCmdShow)

The code will open any file where the extension has been associated with a program, but the problem is as soon as the file opens, the form goes back to Access instead of the file that's been opened.  nCmdShow is a numeric value that is supposed to set whether the program is opened minimized, maximized, etc, but it doesn't matter what numeric value I use here, the application still minimizes after opening.
LVL 6
Mach1proAsked:
Who is Participating?
 
GRayLConnect With a Mentor Commented:
Add the line:

AppActivate iRet
0
 
GRayLCommented:
Type Alt+F11 to get to the VBA window, and enter AppActivate in the Help window.  Also read up on Shell
0
 
Mach1proAuthor Commented:
That seems to work for most applications. Tends to throw up an error when activating Excel. Since Excel isn't going to be launched that much, I just trapped the error and went with it.
Thanks
0
 
GRayLCommented:
Thanks, glad to help.  No reason I can think of why it should not work for Excel.  Go to the VBA window and in the immediate pane repeat the code you used to Open Excel.  Here you execute one line at a time.  Make sure you have the path for both Excel, and the spreadsheet down correctly, and don't forget the double quotes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.