My ultimate goal is to automate using VBA to open a browser, and input username and password for a website, and then click login to further navigate to different pages and download files!
I want to begin with the simplest trial, however, of doing a Google search! I think the idea would be similar because both require to input something and click something.
I found in IE -> Tools(Alt+X) -> F12 Developer Tools can show html codes of website, and even more convenient, it seems I can select regions and get keywords that I'm interested in! Here are 2 screenshots of those regions, the first one is for the search bar, I found "input name = "q", and the second one is for the search button, where I found "input name = "btnK".
And here are my codes:
Sub test()
Set IE = CreateObject("InternetExplorer.Application")
my_url = "https://www.google.ca/?gws_rd=ssl"
IE.Visible = True
IE.navigate my_url
'For example, if I want to search "123"
IE.Document.getElementById("q").Value = "123"
'Click the "Search" button
IE.Document.getElementById("btnK").Click
End Sub
It returns error at IE.Document.getElementById("q").Value = "123",
Method 'Document' of object 'iwebbrowser2' failed.
Don't understand where has gone wrong. I'm really new to how to use VBA to control browsers... Please help, thank you all!