FractalWalk
Technical User
I am trying to run macros in excel VBA to open a web page and interact with forms. The code works great but sometimes the opened browser window is not brought to the front, so I am trying to use a couple of APIs to make that happen:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
So to bring the window to the top I need the handle and to get the handle I am using the FindWindow API. I am using "IEFrame" for the class and that works. However, I want to utilize the window name as well in case a user has more than one IE window open. The problem is that I have no idea how to find the window's name. I am referencing a window opened by a static URL, so I am guessing the name is not variable. But is it a window property I should see in the source code? Is that something that IE should be dipslaying?
Everything I have seen says that to get the window name just pass the handle to an API. But that is a catch 22 as the handle is what I am trying to get from the window name. Any thoughts?
Here is the relvant section fo my code:
Code:
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate URL1
'sub to wait for page to load, show/don't show page and pause 2 seconds
Call Opened_Site(True)
hndl = FindWindow("IEFrame", WhatDoIPutHere?)
iret = BringWindowToTop(hndl)