none
Automating Internet Explorer RRS feed

  • Question

  • Hello, 

    I am trying to use Access VBA to automate IE.  The code below opens a url in IE and then pauses while the user logs in and downloads a file.  Once the user closes the IE window then VBA execution resumes to do some other processing.  

    Sub GetExport()
    
        Dim appIE As Object                               ' InternetExplorer
        Dim strURL As String
        Dim strFile As String
    
        Set appIE = CreateObject("InternetExplorer.Application")
    
        strURL = "https://www.blahblahblah.com/login.aspx"
    
        With appIE
            .Navigate strURL
            .Visible = True
        End With
    
        '-----------------------------------------------------------------------------------
        ' loop until the page finishes loading
        '-----------------------------------------------------------------------------------
        Do While appIE.busy
        Loop
        '-----------------------------------------------------------------------------------
        ' Maximize the window, let user do their bit.
        '-----------------------------------------------------------------------------------
        apiShowWindow appIE.hwnd, SW_MAXIMIZE
        '-----------------------------------------------------------------------------------
        ' Pause while user logs in and downloads file.
        ' When user closes IE, app will no longer be visible.
        '-----------------------------------------------------------------------------------
        Do While appIE.Visible
            DoEvents
        Loop

    Everything works well except the "do while appIE.visible" loop causes occasional dropped keystrokes while the user enters user id and password in the website.  Is there a better way to pause VBA while the user completes their work in the browser?  Thanks.

    -Bruce

    Thursday, August 31, 2017 5:56 PM

Answers

  • I'm not sure if ShellExecute gives me a way shell modally or know when the shelled process is done, but that's a good thought since it's only the IE object that is affected adversely by my do loop.  

    At any rate I resolved by simply replacing the do loop with a "Click ok to continue" message box. :)  Thanks though!

    -Bruce

    Thursday, August 31, 2017 6:31 PM

All replies

  • Hi Bruce,

    You might try using ShellExecute API rather than creating an IE object.

    Just my 2 cents...

    Thursday, August 31, 2017 6:01 PM
  • I'm not sure if ShellExecute gives me a way shell modally or know when the shelled process is done, but that's a good thought since it's only the IE object that is affected adversely by my do loop.  

    At any rate I resolved by simply replacing the do loop with a "Click ok to continue" message box. :)  Thanks though!

    -Bruce

    Thursday, August 31, 2017 6:31 PM
  • Hi,

    Glad to hear you got it sorted out. Good luck with your project.

    Thursday, August 31, 2017 6:33 PM
  • There are many events that could help. There is an onquit or onexit event but if you are satisfied with what you have then I won't bother to be more specific about that. Other events that might help are downloadbegin and downloadcomplete; events like that at least.

    The code in my Introduction to Web Site Scraping article was an Access macro initially.



    Sam Hobbs
    SimpleSamples.Info

    Friday, September 1, 2017 4:58 PM
  • Hello Bruce,

    Since your issue has been resolved, I suggest you mark your solution as answer to close this thread.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 5, 2017 7:20 AM
    Moderator
  • Hi Sam, I did think briefly about how to implement as a class so I could sink the event handlers you mentioned but I was in a hurry and just dropped a messagebox() in my code to stop everything.  Thanks though!

    -Bruce

    Tuesday, September 5, 2017 7:50 PM
  • Hello Bruce,

    As your issue has been resolved, please mark your solution as answer to close this thread. If you have any new issues, please feel free to post new threads. Thanks for your understanding.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 8, 2017 7:07 AM
    Moderator