Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:06:46+00:00 2026-05-26T09:06:46+00:00

In my VBA application I start IExplore process with: Shell sIE, vbMaximizedFocus Now I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:06:47+00:00Added an answer on May 26, 2026 at 9:06 am

    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.

    Global Const SW_MAXIMIZE = 3
    Global Const SW_SHOWMINIMIZED = 2
    Global Const SW_SHOWNORMAL = 1
    
    Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
                (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
    Public Function Test()
    
        Dim ie As Object
    
        'reference "Microsoft Internet Controls (ieframe.dll)", and
        'cast ie as "InternetExplorer" if you wish to use intellisense
        Set ie = CreateObject("InternetExplorer.Application")
    
        ie.Visible = True
    
        apiShowWindow ie.hwnd, SW_MAXIMIZE
    End Function
    

    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:

    Public Type RECT
       x1 As Long
       y1 As Long
       x2 As Long
       y2 As Long
    End Type
    
    Public Enum SetWindowPosFlags
         SWP_ASYNCWINDOWPOS = &H4000
         SWP_DEFERERASE = &H2000
         SWP_DRAWFRAME = &H20
         SWP_FRAMECHANGED = &H20
         SWP_HIDEWINDOW = &H80
         SWP_NOACTIVATE = &H10
         SWP_NOCOPYBITS = &H100
         SWP_NOMOVE = &H2
         SWP_NOOWNERZORDER = &H200
         SWP_NOREDRAW = &H8
         SWP_NOREPOSITION = SWP_NOOWNERZORDER
         SWP_NOSENDCHANGING = &H400
         SWP_NOSIZE = &H1
         SWP_NOZORDER = &H4
         SWP_SHOWWINDOW = &H40
    End Enum
    
    Public Enum SpecialWindowHandles
        HWND_TOP = 0
        HWND_BOTTOM = 1
        HWND_TOPMOST = -1
        HWND_NOTOPMOST = -2
    End Enum
    
    
    'taken from IE's ReadyState MSDN Specs
    Enum READYSTATE
        READYSTATE_UNINITIALIZED = 0
        READYSTATE_LOADING = 1
        READYSTATE_LOADED = 2
        READYSTATE_INTERACTIVE = 3
        READYSTATE_COMPLETE = 4
    End Enum
    
    Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long, ByVal hWndInsertAfter As SpecialWindowHandles, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
    
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Public Sub RunIt()
    
        Dim ie As Object
        Dim r As RECT
    
        Set ie = CreateObject("InternetExplorer.Application")
    
            'draws a 400 pixel x 400 pixel window in position 0 (top left)
        r.x1 = 0
        r.y1 = 0
        r.x2 = r.x1 + 400
        r.y2 = r.y1 + 400
    
            'HWND_TOP sets the Z Order to our IE Object
            'x2 - x1 ==> Width (In Pixels)
            'y2 - y2 ==> Height (In Pixels)
        SetWindowPos ie.hWnd, HWND_TOP, r.x1, r.y1, (r.x2 - r.x1), (r.y2 - r.y1), SWP_ASYNCWINDOWPOS
    
        ie.Visible = True
        ie.Navigate "www.google.com"
    
        'wait until navigated
        Do While ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE
            Sleep 60
        Loop
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created an application in Excel VBA that needs to run a batch file
I have some VBA code that needs to talk to a running c# application.
So, let's say that I have a VBA application inside of whatever Office Application.
I am wrapping up an office application (VBA) that makes a call to a
I want to write some VBA script so that when I start my access
I have a VB6/VBA application that hooks into Excel and loads a workbook. It
I should start by saying that I know no VBA I have to enter
I have a VBA application that runs every day. It checks a folder where
I'm experiencing a problem with my VBA application. I need to define a Recordset
I have an application in VBA that gives to my VB.Net dll one bi-dimensional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.