Results 1 to 5 of 5

Thread: Automate some steps in IE, with VBA

  1. #1
    Neophyte polonic's Avatar
    Join Date
    Aug 2020
    Posts
    3
    Articles
    0
    Excel Version
    2016

    Automate some steps in IE, with VBA



    Register for a FREE account, and/
    or Log in to avoid these ads!

    hello everybody,
    i`m here to search for some help, if is possible.

    i was trying by myself to scrap some vba code to automate some steps in a IE windows. i saw some tutorials on YT, try using some code, but at the end, when i saw thinking that i made`t, the machine where i was trying to use the script, was not recognize this part SetForegroundWindow HWNDSrc (that suppose to bring forward/activate the IE window).
    i mentioned from the beginning, that i don`t use to search for ID name, cause is an closed program that work in IE.

    what i what this code to do:
    1. search for IE windows with the string IBAN in here name.
    2. activate/bring forward the IE
    3. use a command like Ctrl&S
    4. use [tab] button like 20 times until is reaching the tab that i need
    5. there will be a combo box where i wanna select something (let`s say something that i write in cell A1
    6. after selection is done, go again 5 [tabs] to go to another combo box.
    7. select again something from cell A2
    8. use a command for save Ctrl&S

    end of the script.

    thx in advance!
    here is the code:

    Code:
    Sub test()
    
    
    
    Dim i As Long
    
    Dim URL As String
    
    Dim IE As Object
    
    Dim objElement As Object
    
    Dim objCollection As Object
    
    Dim HWNDSrc As Long
    
    
    
    marker = 0
    
    Set objShell = CreateObject("Shell.Application")
    
    IE_count = objShell.Windows.Count
    
    For x = 0 To (IE_count - 1)
    
    On Error Resume Next ' sometimes more web pages are counted than are open
    
    my_url = objShell.Windows(x).Document.Location
    
    my_title = objShell.Windows(x).Document.Title
    
    
    
    If my_title Like "*" & "IBAN" & "*" Then 'compare to find if the desired web page is already open
    
    Set IE = objShell.Windows(x)
    
    marker = 1
    
    Exit For
    
    Else
    
    End If
    
    Next
    
    
    
    If marker = 0 Then
    
    MsgBox ("A matching webpage was NOT found")
    
    Else
    
    'MsgBox ("A matching webpage was found")
    
    'Get Window ID for IE so we can set it as activate window
    
    HWNDSrc = IE.HWND
    
    'Set IE as Active Window
    
    SetForegroundWindow HWNDSrc
    
    
    
    
    
    For Each itm In IE.Document.all
    
    If itm = "[object HTMLInputElement]" Then
    
    n = n + 1
    
    If n = 3 Then
    
    itm.Value = "orksheet"
    
    itm.Focus
    
    'Activates the Input box (makes the cursor appear)
    
    
    
    Application.SendKeys "^{N}", True
    
    Application.SendKeys "{TAB}", True
    
    Application.SendKeys "{TAB}", True
    
    
    
    
    
    Application.SendKeys "{R}", True
    
    
    
    
    
    'until keystroke has finished before proceeding, allowing
    
    'javascript on page to run and filter the table
    
    GoTo endmacro
    
    End If
    
    End If
    
    Next
    
    
    
    Unload IE
    
    endmacro:
    
    Set IE = Nothing
    
    Set objElement = Nothing
    
    Set objCollection = Nothing
    
    End If
    
    End Sub

  2. #2
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,808
    Articles
    0
    Excel Version
    O365
    Cross-posted at Excel Forum

  3. #3
    Neophyte polonic's Avatar
    Join Date
    Aug 2020
    Posts
    3
    Articles
    0
    Excel Version
    2016
    sorry, did not know that i cannot cross post to some other forums

  4. #4
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,808
    Articles
    0
    Excel Version
    O365
    You can, but most people like you to put a link to any other forums that you post to. That way, we can choose to not bother, check if someone has already solved it, or just help anyway.

  5. #5
    Neophyte polonic's Avatar
    Join Date
    Aug 2020
    Posts
    3
    Articles
    0
    Excel Version
    2016
    I was trying to find something like what I need, I found and scrap some code, but like I said in another post, is not working on the computer that I need. I was trying to declare it for 64-bit, but when I do that, the rest of the code is not working anymore.

    I tried to to break the code in steps, but the only thing that I needed now is to find an alternative for the ie windows to be active/bring forward.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •