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 8297227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:19:59+00:00 2026-06-08T15:19:59+00:00

The macro I am building takes names from an Excel spreadsheet, opens Internet Explorer,

  • 0

The macro I am building takes names from an Excel spreadsheet, opens Internet Explorer, and searches the online directory. After searching the directory, it pulls up a Java form with the manager’s name in it. I am able to manually tab to the manager name, right click, copy shortcut, and then post it back on the spread sheet. However, I am having problems with consistent tabbing and copying the shortcut.

  1. Is there a simple way of bringing focus back onto the IE window?
  2. How do you copy a shortcut without manually clicking it?

Code:

Sub Macro1()
'
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")

ie.Visible = True
ie.navigate "****url****"

While ie.busy
    DoEvents
Wend

ie.document.getElementById("SSOID").Value = "Z19516732"
ie.document.getElementById("Advanced").Checked = False
ie.document.all("Search").Click

'this loop is to slow the macro as the java form is filled from the search
For i = 1 To 400000000  
    i = i + 1
Next i

'ie.Object.Activate
ie.document.getElementById("Advanced").Checked = False
ie.document.getElementById("SSOID").Focus
Application.SendKeys "{TAB 6}" ', True

'bring up the control menu/right click
Application.SendKeys "+{F10}"

'copy shortcut is 8 items down on the list
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"

'enter was not working so the shortcut for the menu is 't'
'SendKeys "{ENTER}"
Application.SendKeys "{t}"

Windows("Book21").Activate
Range("A1").Select
ActiveSheet.Paste

End Sub
  • 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-06-08T15:20:01+00:00Added an answer on June 8, 2026 at 3:20 pm

    At the beginning of your module, put this line of code:

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
    

    This is called a Declare Statement and will allow you to access the SetForegroundWindow function that is built into Windows. This function lives in the user32 DLL of the Windows system. There are actually a number of other functions among multiple DLLs that are accessible to VBA in this way (see link for more examples).

    In your code, while interacting with your IE object, record the HWND (handle to that window) like so:

    Dim HWNDSrc As Long
    HWNDSrc = ie.HWND
    

    Then, after you’ve interacted with Java, use this to continue:

    SetForegroundWindow HWNDSrc
    

    This tells the Windows system to set the window identified by the HWND as the foreground window (as the name implies).

    However, this may not be necessary, depending on how you are interacting with IE. In other words, if you don’t need to see/touch the window, you can still interact using the object as you have in your code already.

    There are ways to get the shortcut you are looking for using code like GetElementById() and GetElementsByTagName() (see here for more info), but it will depend on how the source was created. e.g. an <a href="...> link should be relatively easy to pull, if you know the HTML source.


    After reviewing your code a second time, I noticed you use a loop to ‘slow down’ the macro. I have a function I use all the time for similar methods of my own. Hopefully this will help in you getting done what you need. I’ve modified my code below from my own original, since I had additional specifics that don’t apply to your case. If there are any errors with it, I can adjust as needed.

    Public Sub WaitForIE(myIEwindow As InternetExplorer, HWND As Long, WaitTime As Integer)
    
        ' Add pauses/waits so that window action can actually
        ' begin AND finish before trying to read from myIEWindow.
    
        ' myIEWindow is the IE object currently in use
        ' HWND is the HWND for myIEWindow
        ' The above two variables are both used for redundancy/failsafe purposes.
        ' WaitTime is the amount of time (in seconds) to wait at each step below. 
        ' This is variablized because some pages are known to take longer than 
        ' others to load, and some pages with frames may be partially loaded,
        ' which can incorrectly return an READYSTATE_COMPLETE status, etc.
    
        Dim OpenIETitle As SHDocVw.InternetExplorer
    
        Application.Wait DateAdd("s", WaitTime, Now())
    
        Do Until myIEwindow.ReadyState = READYSTATE_COMPLETE
            ' Wait until IE is done loading page and/or user actions are done.
        Loop
        
        Application.Wait DateAdd("s", WaitTime, Now())
        
        While myIEwindow.Busy
            DoEvents  ' Wait until IE is done loading page and/or user actions are done.
        Wend
            
        On Error Resume Next
        ' Make sure our window still exists and was not closed for some reason...
        For Each OpenIETitle In objShellWindows
            If OpenIETitle.HWND = HWND Then
                If Err.Number = 0 Then
                    Set myIEwindow = OpenIETitle
                    Exit For
                Else
                    Err.Clear
                End If
            End If
        Next OpenIETitle
        On Error GoTo 0
        
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a macro to export data from a custom outlook form to
I am trying to write a macro for Building my application, kicking off an
Cody has been building a Pythonic Macro Syntax. He says These macros allow you
This macro should activate tabs in sequence from 1th to 5th and then again.
Clojure offers a macro called doto that takes its argument and a list of
I'm designing/building a system of classes that all derive from a single base class.
I have written a macro to dump excel cells on to a notepad file.
I usually pass macro definitions from "make command line" to a "makefile" using the
I'm building some Word 2003 macro that have to be put in the %APPDATA%\Microsoft\Word\Startup
I am building my own web server and want to serve from it a

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.