In my VBA application I start IExplore process with:
Shell sIE, vbMaximizedFocus
Now I need to resize created window. For that I can use SetWindowPos function, which takes a handle to the window as one of the arguments. And I don’t have that handle…
I would use FindWindowLike function (which goes threw windows, compares caption with pattern and returns array of handles of windows with matching caption), but I cann’t rely on window caption. I cann’t just resize all of the IE windows also.
So, I was thinking of using SOMETHING that would give me a handle of a window to the process I just ran. Shell does not provide this.
I have some example code, how to do this in C++ using CoCreateInstance function:
CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)&m_pBrowser);
if (m_pBrowser)
{
pom = buffer;
m_pBrowser->put_Visible(VARIANT_TRUE);
m_pBrowser->Navigate(pom, &(_variant_t(flaga)), &vDummy, &vDummy, &vDummy);
m_pBrowser->get_HWND((long *)&hWnd);
if (hWnd != NULL)
{
...
...
I would’ve port this to VBA, but I’m not so sure, what to put for fourth parameter:
riid
[in] Reference to the identifier of the interface to be used to communicate with the object.
Well I don’t know witch interface I should pass… I’m not even sure if I can use it in VBA.
So. Is there a way to execute process, which would provide me a handle to it’s window?
To go along with Tim Williams. You can do it quite easily by using create object to get an IE object vs using a shell call. This makes it easier since you have access to the object, and don’t need try to look up the window handle after the fact.
If you are dealing with multiple monitors or need more control over the window, then it gets a little more tricky. Here is one of my previous answers to address that: Is it possible to launch a browser window in VBA maximized in the current monitor?
EDIT. Set window to certain position: