Automate some steps in IE, with VBA

polonic

New member
Joined
Aug 13, 2020
Messages
3
Reaction score
0
Points
0
Excel Version(s)
2016
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:
[COLOR=#333333]Sub test()[/COLOR]



[COLOR=#333333]Dim i As Long[/COLOR]

[COLOR=#333333]Dim URL As String[/COLOR]

[COLOR=#333333]Dim IE As Object[/COLOR]

[COLOR=#333333]Dim objElement As Object[/COLOR]

[COLOR=#333333]Dim objCollection As Object[/COLOR]

[COLOR=#333333]Dim HWNDSrc As Long[/COLOR]



[COLOR=#333333]marker = 0[/COLOR]

[COLOR=#333333]Set objShell = CreateObject("Shell.Application")[/COLOR]

[COLOR=#333333]IE_count = objShell.Windows.Count[/COLOR]

[COLOR=#333333]For x = 0 To (IE_count - 1)[/COLOR]

[COLOR=#333333]On Error Resume Next ' sometimes more web pages are counted than are open[/COLOR]

[COLOR=#333333]my_url = objShell.Windows(x).Document.Location[/COLOR]

[COLOR=#333333]my_title = objShell.Windows(x).Document.Title[/COLOR]



[COLOR=#333333]If my_title Like "*" & "IBAN" & "*" Then 'compare to find if the desired web page is already open[/COLOR]

[COLOR=#333333]Set IE = objShell.Windows(x)[/COLOR]

[COLOR=#333333]marker = 1[/COLOR]

[COLOR=#333333]Exit For[/COLOR]

[COLOR=#333333]Else[/COLOR]

[COLOR=#333333]End If[/COLOR]

[COLOR=#333333]Next[/COLOR]



[COLOR=#333333]If marker = 0 Then[/COLOR]

[COLOR=#333333]MsgBox ("A matching webpage was NOT found")[/COLOR]

[COLOR=#333333]Else[/COLOR]

[COLOR=#333333]'MsgBox ("A matching webpage was found")[/COLOR]

[COLOR=#333333]'Get Window ID for IE so we can set it as activate window[/COLOR]

[COLOR=#333333]HWNDSrc = IE.HWND[/COLOR]

[COLOR=#333333]'Set IE as Active Window[/COLOR]

[COLOR=#333333]SetForegroundWindow HWNDSrc[/COLOR]





[COLOR=#333333]For Each itm In IE.Document.all[/COLOR]

[COLOR=#333333]If itm = "[object HTMLInputElement]" Then[/COLOR]

[COLOR=#333333]n = n + 1[/COLOR]

[COLOR=#333333]If n = 3 Then[/COLOR]

[COLOR=#333333]itm.Value = "orksheet"[/COLOR]

[COLOR=#333333]itm.Focus[/COLOR]

[COLOR=#333333]'Activates the Input box (makes the cursor appear)[/COLOR]



[COLOR=#333333]Application.SendKeys "^{N}", True[/COLOR]

[COLOR=#333333]Application.SendKeys "{TAB}", True[/COLOR]

[COLOR=#333333]Application.SendKeys "{TAB}", True[/COLOR]





[COLOR=#333333]Application.SendKeys "{R}", True[/COLOR]





[COLOR=#333333]'until keystroke has finished before proceeding, allowing[/COLOR]

[COLOR=#333333]'javascript on page to run and filter the table[/COLOR]

[COLOR=#333333]GoTo endmacro[/COLOR]

[COLOR=#333333]End If[/COLOR]

[COLOR=#333333]End If[/COLOR]

[COLOR=#333333]Next[/COLOR]



[COLOR=#333333]Unload IE[/COLOR]

[COLOR=#333333]endmacro:[/COLOR]

[COLOR=#333333]Set IE = Nothing[/COLOR]

[COLOR=#333333]Set objElement = Nothing[/COLOR]

[COLOR=#333333]Set objCollection = Nothing[/COLOR]

[COLOR=#333333]End If[/COLOR]

[COLOR=#333333]End Sub[/COLOR]
 
sorry, did not know that i cannot cross post to some other forums :(
 
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.
 
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.
 
Back
Top