Microsoft Excel - Looping Though Windows, Activate Particular Window

Asked By Rajender Prasad on 17-May-13 08:58 AM

Dear All,

I have windows titles like Maintain, Create, Mainmenu – Information. I am using the following code, and my problem is, though user open the above windows in any of the order, first task should perform on “maintain” page then “create” and then last “Mainmenu – Information”.

Now, what is happing , if title is create, then it is directly going to “create” but that is wrong because I have to do something on “maintain” first and grab some values then come to “create”.

Can anyone suggest me how can achieve this.

Dim allExplorerWindows As New SHDocVw.ShellWindows
Set allExplorerWindows = New SHDocVw.ShellWindows
Dim IeGPS As SHDocVw.InternetExplorer
Dim foundFlag As Boolean
    foundFlag = False
For Each IeGPS In allExplorerWindows
         If InStr(IeGPS.LocationURL, "my web site") <> 0 Then
nameofweb = IeGPS.document.Title
if nameofweb=”maintain” then
--do something
 End if
if nameofweb=”create” then
--do something
 End if
if nameofweb=” Mainmenu – Information.” then
--do something
 End if
Next iegps


Robbe Morris replied to Rajender Prasad on 17-May-13 09:06 AM
You'll want to store the name of the current window and compare it to the requested window before executing your logic.
Your current code has no idea what the current window is and thus couldn't apply "task order" logic to it.
Rajender Prasad replied to Robbe Morris on 17-May-13 09:13 AM
thanks for the reply.
I stored in nameofweb, if name of web is  "maintain" it should perform some action.
But If the title of the first window "create" which i dont want to perform before "maintain".
Second time my window title is "maintain", then It will do watever I want but, it is not looping once again to catch "create"..

All I require is, 1st Go to "MAINTAIN" 2nd GOTO "CREATE" then 3rd "Main Menu Information " .

I am so poor in wrting the logics, can u please write some logic for me...

That would be great/

Robbe Morris replied to Rajender Prasad on 17-May-13 09:17 AM
Actually, you are not.  In the "-- do something logic", you want to set a variable called lastWindow = nameofweb.

You can then check the value of lastWindow when the user attempts to move onto the next window and determine what you'll.  As per the thread yesterday, you are making this project a lot harder than it needs to be by attempting to work with windows in this fashion rather than a controlled environment in Excel VBA forms using the WebBrowser control.
Rajender Prasad replied to Robbe Morris on 17-May-13 09:24 AM
yes, may be you are right.. but I am poor in vba.. I am just digging nowadays as I got to move to work on vba for whole day.

So you want me to save the name of web page in one variable. I will check but  i have doube that if "maintain" is not first web page for loop is not looping to get "maintain" again.. becasue its already came on.

Can u pls write some sample code waht I am trying to implement