I'm new to Excel macro. I have a macro which was given to me by an ex-teammate who has left the team many years already. When the macro runs, it invokes IE, opens a page, and then automate data-entry and mouse-clicks.
Now that IE will become unsupported. We have to use Edge. How can I convert this macro so that it will invoke Edge and do the same automation thing on Edge?
I searched on many web community and most seems to tell me that I need Selenium. Problem is that I cannot install Selenium due to my company's policy.
Of all the suggestions I could find on web community, I found this one seems to be addressing my problem : Automating Edge Browser using VBA without downloading Selenium
I followed exactly the suggestion and installed the registry :
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\Main] "NotifyDisableIEOptions"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode] "EnableGlobalWindowListInIEMode"=dword:00000001
After that, the IE on my machine is disabled, and I can no longer see it on the Windows START menu.
Then, I tried to run my macro again but it is still invoking IE.
Is there any expert here who can give me some advice so that my macro will run on Edge and the code can also run on Edge ?
I'm really new to macro. Appreciate if any expert here can point out to me exactly which line of code I need to change and how to change. Thanks a ton !
This is excerpt of my macro [masked a little to hide sensitive info]
Dim Element As HTMLButtonElement
Dim IE As InternetExplorer, URL as String, HTMLDoc as HTMLDocument
Dim value_element as String
.
.
.
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "https://example.com"
Do While IE.Busy or IE.readState <> READYSTATE_COMPLETE: DoEvents: Loop
If Instr(IE.Document.body.innerText, "There is a problem with this website's security certificate.") >0 Then
IE.Document.links(1).click
Do While IE.Busy or IE.readState <> READYSTATE_COMPLETE: DoEvents: Loop
End If
Set HTMLDoc = IE.Document
HTMLDoc.getElementById("ElementA").Value = value_element
For Each Element in HTMLDoc.getElementsByTagName("Input")
If Element.Value = "Submit" Then
Call Element.click
Do While IE.Busy or IE.readState <> READYSTATE_COMPLETE: DoEvents: Loop
Exit For
End If
Next Element
CodePudding user response:
I try to refer to the steps and configured the registry keys. It disabled the IE 11 browser. I try to test the VBA IE automation code and found that it launches the IE browser window. It looks like this is the expected behavior at this moment.
Also, you could expect that your VBA code will work and launch the IE window after the IE retirement.
Please see this IE retirement FAQs
I ran into issues with my application which utilizes IE through automation. Will this be fixed? (Updated: April 14, 2022)
As part of the IE 11 application retirement, certain COM automation scenarios were inadvertently broken. These IE COM objects have been restored to their original functionality as of the Windows 11 November 2021 “C” update and the Windows 10 March 2022 “B” update. The COM scenarios will also continue to work after the IE11 desktop application is disabled after June 15, 2022. If you continue to experience issues after taking the update, please contact App Assure for remediation assistance.
At present, there is no information available that the VBA automation code will automate the IE mode in the Edge browser. You need to use the Selenium web driver to automate the IE mode in the Edge browser.
CodePudding user response:
Change the Internet Explorer compatibility settings in Edge (see How to use internet explorer mode in edge).
Additionally, add the urls to the Internet Explorer mode list (Settings -> Default browser -> Internet Explorer mode pages).