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

  • Home
  • SEARCH
  • 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 7579659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:43:39+00:00 2026-05-30T17:43:39+00:00

I am trying to automate JavaScript forms/pages in IE7 using VBA. I have already

  • 0

I am trying to automate JavaScript forms/pages in IE7 using VBA. I have already determined that I must use sendkeys to move past a JS alert pop-up. Since this process will take some time to run, the intent of this function is for users to be able to run the process in the background and do other things. This is not my preferred option while working with sendkeys, but I don’t know that I have another choice (other than force users to wait for the process to complete, which I can use as a last resort option).

In order to prevent issues with sendkeys going to the wrong application, I am forcing the focus to the current IE window. In doing so, the focus winds up on the main IE window, and not the alert box. If I try to reset the focus by pausing the codes, then manually clicking on the IE window, the focus does go to the alert box. In other words, it appears setting the focus using code is the culprit.

I have been unsuccessful in finding a way to capture the alert box using my automation, otherwise I would have tried to activate the button control on it.

I am setting the focus using this code:

Private Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
Sub WaitForIE(myIEWindow As InternetExplorer, HWND As Long, Optional CheckForAlert As Boolean = False)
'OTHER CODE
    While myIEWindow.Busy
        DoEvents  ' Wait until IE is done loading page and/or user actions are done.
        Application.Wait DateAdd("s", 1, Now()) ' Wait one second per cycle so as not to use too much CPU
        If CheckForAlert Then 'Only check for alert box when certain pages are loaded
            Dim IEPage As Variant
            Dim PlaceHolder As Long
            Dim SearchFor As String

            SearchFor = "userMessage = '"
            Set IEPage = myIEWindow.Document.Frames(2).Document.Body
            PlaceHolder = InStr(IEPage.innerhtml, SearchFor)
            If PlaceHolder > 0 Then
                If InStr(PlaceHolder + Len(SearchFor), IEPage.innerhtml, "'") > PlaceHolder + Len(SearchFor) + 1 Then ' if userMessage does not equal '' then the alert will show, so clear alert box
                    SetForegroundWindow HWND 'HWND is the HWND of the myIEWindow
                    Application.SendKeys "{ENTER}", True
                End If
            End If

           Set IEPage = Nothing

        End If
    Wend
' MORE CODE
End Sub

Is there an alternative to this method (setting focus), or is there another step to this method I am missing?

  • 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-30T17:43:40+00:00Added an answer on May 30, 2026 at 5:43 pm

    The trick is to send a {TAB} before sending your {ENTER}, this will bring focus to the alert box

    Application.SendKeys "{TAB}{ENTER}", True
    

    should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to automate a gdb session using the --command flag. I'm trying to
I am trying to automate functional testing of a server using a realistic frequency
I am trying to automate VC++ build via an addIn written using VB.NEt so
I am trying to automate iPHone UI testing throught JavaScript. I am in a
Trying to find a way to automate the API from javascript comments.
I'm trying to automate a process on a remote machine using a python script.
I am trying to automate logging into Photobucket for API use for a project
I am trying automate a login process to my web application using Selenium-Python Client
I'm trying to automate the download of some data from a webform. I'm using
I'm trying to automate some stuff in SVN, and part of that is copying

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.