G
Guest
There could be something in the code of the app you are-----Original Message-----
Hi,
I've searched through the previous posts, and I don't think what I want
to do is possible with VBA in Excel 2002 (SP-2) but I'll pose the
question just in case.
I'm using a Shell command in an Excel VBA macro to run an external app,
but it isn't quite working as I had anticipated.
Im using the following syntax:
MyAppID = Shell("App_Path&Name.EXE", vbHide)
Which works and the program loads OK, but the problem is no matter what
windowstyle argument I use: vbHide, vbMinimizedFocus,
vbMinimizedNoFocus or even omitting an argument (which is meant to
according to the help file :"-If windowstyle is omitted, the program is
started minimized with focus.-") the application window opens in front
of the Excel Window (which I want to retain focus).
The Excel task on the start/task bar flashes, and must be clicked on to
once again become the window that is in focus. The application being
loaded acts as a conduit between a data provider and Excel and as such
must remain open for the rest of the macro to complete successfully. As
a consequence I've coded the macro to display a message box, that must
be clicked before the macro continues, but you must click on the Excel
task on the start/task bar in order to see this message box. I would
prefer the application window to open in a minimised state, but it
appears to open in the previously used state. I.e. If it was closed the
previous time maximised then it opens maximised, or if it only took up
the half the screen, it again opens to the same position (half the
screen).
The logical conclusion would be to close the program in a minimised
state each time, but as others use the application for different
purposes from the same PC, I can not assume that this will be the case.
Closing the application window prior to the macro completing processing
isn't an option either.
A couple of things to note: I'm using Win XP pro, on a Dell corporate
workstation, and the MyAppID is not declared as a variable of any type
(though when I did declare it, I got the same result, so I don't think
it is that).
So is it possible to somehow use the MyAppID variable to control the
opened app window to minimise the window from the VBA code in Excel? If
not is there another way to minimise the app, without doing it
manually? Why is the window state command I've used being ignored?
Thanks in Advance.
Az
starting that forces it to take focus after it is started,
which might explain the behaviour you are seeing.
My first suggestion, if you have not yet considered it, is
to put an AppActivate statement right after your Shell
statement to force Excel to become again the active
application, i.e:
MyAppID = Shell("App_Path&Name.EXE", vbHide)
AppActivate "Microsoft Excel"
Other than this, you can do a lot to control the behavior
of Windows but it would require using Windows API calls -
not an easy topic for the uninitiated, but for info check
out:
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/winui/winui/windowsuserinterface/windowing/windows.asp