Automate some steps in IE, with VBA

polonic

New Member
Joined
Aug 13, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top