I wrote a script that will open a workbook and run the macro within the workbook. The macro is supposed to open internet explorer and log into a website using the SendKeys
command. The issue that I have is that internet explorer opens in the background while Excel is running in the front. Essentially, I would like the newly opened internet explorer to be in the front and selected so that I could use the SendKeys
command. I know that the macro works when I run it manually and for some reason it also rarely works (after computer restart). I'm not sure if this is a timing issue.
The reason why I have to use SendKeys
is because the log in button will only work if you manually type in the id and password. I also tried disabling the button using this but it didn't work so I have to use SendKeys
.
With .querySelector("#subBtn")
.disabled = False
.Click
Multiple people already asked about this question but it seems like there isn't a definitive answer. Here are the codes that I tried.
Dim ie As New InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
CreateObject("WScript.Shell").AppActivate "Internet Explorer"
ie.Navigate "Website here"
I also tried showing the i.e after the website loaded and it didn't work.
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "website here"
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ie.visible = True
DoEvents
I also tried minimizing excel first and then setting i.e. visible=false
and turn it back to true. This brings internet explorer to the front, but it is not selected (focus?) so the SendKeys
command won't work.
ActiveWindow.WindowState = xlMinimized
ie.Visible = False
DoEvents
ie.Visible = True
I would like to have internet explorer in the front and selected so that I can SendKeys
.