Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shortcut fires Script that opens Excel form and API adds minimize + taskbar. Second instance faulty

Status
Not open for further replies.

pxcpyc

Technical User
Aug 8, 2010
4
0
0
AU
I have a desktop shortcut to a vbs script (below) that opens Excel (invisible) and displays a form. I use Windows API to add an icon to the titlebar of the form, to add a minimize button to the form, and add the programs name to the Taskbar. This works perfectly.
If I double click on the desktop shortcut to add a second instance of my Excel program, these API features do not work correctly - the icon does not appear, the form minimizes to the bottom LHS of the screen instead of to the Taskbar, and the name is not added to the Taskbar. (I use other API commands within the program and they seem to work perfectly).
Instead of using the desktop shortcut, if I double click on the vbs script, the second instance behaves perfectly.
Any suggestions as to what is happening here?
thanks

This script is located in the same folder as the Excel file "Test1.xlsm":
Dim xlApp
Dim PathFileName
PathFileName = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName))) & "Test1.xlsm"
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open PathFileName
Set xlApp = Nothing
 
I found that if I open 2 separate instances of my test program from the 1 script, then they both work perfectly:

Dim xlApp
Dim PathFileName
PathFileName = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName))) & "Test1.xlsm"

Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open PathFileName

Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open PathFileName

Set xlApp = Nothing

This suggests the problem can be fixed with Vbscript alone, even if it is related to the code behind Windows shortcuts and or Windows API. My lack of understanding of what is happening here means I do not know how to take advantage of this. I want the user to be able to click the shortcut 1 time to open 1 instance of the program. Then to click it a second time to open a second instance. Any suggestions appreciated.

thanks
 
What are the properties of the shortcui ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
For information of other readers, I have found a way forward:

I open my program as described in the first post above then open a second form (off the display area) which I then close, then the API functions work correctly for multiple instances.

My fix is in the VBA code area rather than the VBScript where I have posted this. I felt that there was some kind of interaction between the vbscript, the windows API and the code behind the desktop shortcut. However, my attempts to isolate the problem were unsuccessful - logic seemed to fail! My final solution was obtained be trial and error and observing the results.

The windows API are in Activate. The end result involves Activate firing twice before the Windows API work perfectly. Even then it is not 100% perfect. It requires the user to click in a form before the API functions are all fully operational. This is a minor limitation.
 
Hi PHV - sorry but I missed your reply somehow
Can you clarify which properties you mean?
My shortcut is the one that windows creates when I right click on my VBscript file.
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top