Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15430

Automate some steps in IE, with VBA

$
0
0
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:

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

Viewing all articles
Browse latest Browse all 15430

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>