VBA Code when Upgrading from IE to Edge

Rman51

New Member
Joined
May 27, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I’m in a Window10/Excel 16 environment. I have been using Internet Explorer (IE) when I scrap data from websites.
Now, I am needing to upgrade to Microsoft Edge. I am having to translate some code and I am finding I need some help.

I used to call the URL AZBlue - Arizona Individual & Family Health Insurance Plans using “IE.navigate”. Ex:
VBA Code:
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://www.azblue.com/individualsandfamilies/"

Now, I can also call the URL in Edge using “ActiveWorkbook.FollowHyperlink Address:=” (and it works just fine). Ex.:
VBA Code:
ActiveWorkbook.FollowHyperlink Address:="https://www.azblue.com/individualsandfamilies/"

But, what I cannot figure out is how to use these other lines of Code with Edge. Here are 3 types of lines of code (disjointed) that I use often and need to know the syntax translation for Edge:

1.
VBA Code:
IE.document.getElementById("lockedcontent_0_maincolumn_2_twocolumn2fb4d204091d44aa08196ef423877fd9f_0_ToolbarUsernameControl").Focus
2.
VBA Code:
IE.document.getElementById("lockedcontent_0_maincolumn_2_twocolumn2fb4d204091d44aa08196ef423877fd9f_0_ToolbarUsernameControl").Value = "MyUserName"
3.
VBA Code:
IE.document.Focus

Of course, any help is greatly appreciated!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
So sorry. I have the same issue. It was working with IE. Now I have a new laptop which has never had IE installed. Now the code doesn't work. I'm also looking for a way to accomplish the same thing in Edge.
 
Upvote 0
Hi guys,

Microsoft says as follows. "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."

Seems IE as a COM, still can be used, but I feel it's about time to switch to handling Edge or Chrome via VBA for scraping.

For scraping, using Selenium Basic from VBA seems to be handy.
As for me, I'm not an Edge user, I prefer Google Chrome. So I', going to try with Google Chrome, but the setting for Edge seems the same as well.
(I just tried with Edge for posting here.)

1)Selenium Basic
Seleniumbasic
Install Selenium Basic from the following link.
Install .NET Framework 3.5 runtime

2)Microsoft Edge WebDriver
Microsoft Edge WebDriver - Microsoft Edge Developer
Rename the downloaded file named msedgedriver.exe to edgedriver.exe then place it in the following folder. (In my case, it has already existed but I replaced it with the downloaded one.)
C:\Users\username\AppData\Local\SeleniumBasic

3)From the Tools menu, choose References to display the References dialog box.
Then check "Selenium Type Library". Your Visual Basic project now has a reference to Selenium's object library. If you open the Object Browser (press F2) and select Selenium's library, it displays the objects provided by the selected object library, as well as each object's methods and properties.

Anyway, here is a sample of how to navigate Edge and it worked for me.

VBA Code:
Option Explicit
#If Win64 Then    'If Excel is 64 bit vers
    Private Declare PtrSafe Function MessageBoxTimeoutA Lib "User32.dll" _
            (ByVal hWnd As LongPtr, _
             ByVal lpText As String, _
             ByVal lpCaption As String, _
             ByVal uType As VbMsgBoxStyle, _
             ByVal wLanguageID As Long, _
             ByVal dwMilliseconds As Long) As Long
#Else    'If Excel is 32 bit vers
    Private Declare Function MessageBoxTimeoutA Lib "User32.dll" _
                                                (ByVal hWnd As Long, _
                                                 ByVal lpText As String, _
                                                 ByVal lpCaption As String, _
                                                 ByVal uType As VbMsgBoxStyle, _
                                                 ByVal wLanguageID As Long, _
                                                 ByVal dwMilliseconds As Long) As Long
#End If

Sub Sample()
    Dim driver
    Dim ret As Long

    'Edge Browser
    Set driver = CreateObject("Selenium.webDriver")

    driver.Start "Edge"
    driver.Get "https://www.mrexcel.com/"

    ret = MsgBox("Do you want to close", vbYesNo)

    If ret = vbYes Then
        'Close Edge Browser
        driver.Quit
        Set driver = Nothing
    End If
End Sub
スクリーンショット 2022-07-22 170026.jpg
 
Last edited:
Upvote 0
I didn't notice that it's an old question asked about 2 years ago. Anyway, hope this helps someone.
 
Upvote 0

Forum statistics

Threads
1,225,398
Messages
6,184,733
Members
453,254
Latest member
topeb

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