VBA – Exploring Microsoft Edge

As part of my previous post VBA – Opening Files and URLs, late one night, I also explored Edge ‘automation’ (and I use that term very loosely here!).

Since everyone is now getting Edge pushed upon them, I thought I should delve a little into what can be done with Edge using VBA to see if it offered any potential advantages for us developers.

Sadly, I was disappointed with my findings. Microsoft has once again decided to do things their own way and longstanding approaches (that work with IE, Firefox, Opera, Brave, …, Access, Excel, Word, …) did not work to automate Edge. I was unable to use my standard code to locate the exe on a system to automate it. Even with the exe known, standard chromium command line switches failed to work. All in all, a very disappointing experience. IMHO, Microsoft has, yet again, missed the mark on this one.

Also, documentation is basically non-existent on the subject, or at the very least buried somewhere that isn’t easy to discover!

Regardless, I did find a couple approaches that did work that I thought I’d share with those of you that need to perform such automation.

Shell Function

The easiest approach to opening a URL in Microsoft Edge is to simply use the Shell function as shown below.

'OpenURL5 "https://www.google.ca"
'Does not work for files
'Opens using Microsoft Edge Browser
Public Sub OpenURL5(ByVal sURL As String)
    Dim sCmd                  As String
    
    sCmd = "start microsoft-edge:" & sURL
    shell "cmd /c """ & sCmd & """", vbHide
End Sub
Does Not Work With Files
As indicated in my code comment, this approach worked fine to open a URL in Edge, but did not work trying to open a file. As such, its use is limited.

ShellExecute API

Because of the above’s limitation, I kept looking and eventually found out that by using the ShellExecute API we could open both files and URLs making for a more versatile function.

'https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
Public Declare Function ShellExecute Lib "shell32.dll" _
                                     Alias "ShellExecuteA" ( _
                                     ByVal hwnd As Long, _
                                     ByVal lpOperation As String, _
                                     ByVal lpFile As String, _
                                     ByVal lpParameters As String, _
                                     ByVal lpDirectory As String, _
                                     ByVal nShowCmd As Long _
                                     ) As Long
'ShellExecute nShowCmd values
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Const SW_MAX = 10
'ShellExecute Return Codes
'0 'The operating system is out of memory or resources.
Private Const ERROR_FILE_NOT_FOUND = 2    'The specified file was not found.
Private Const ERROR_PATH_NOT_FOUND = 3    'The specified path was not found.
Private Const ERROR_BAD_FORMAT = 11    'The .exe file is invalid (non-Win32 .exe or error in .exe image).
Private Const SE_ERR_ACCESSDENIED = 5    'The operating system denied access to the specified file.
Private Const SE_ERR_ASSOCINCOMPLETE = 27    'The file name association is incomplete or invalid.
Private Const SE_ERR_DDEBUSY = 30    'The DDE transaction could not be completed because other DDE transactions were being processed.
Private Const SE_ERR_DDEFAIL = 29    'The DDE transaction failed.
Private Const SE_ERR_DDETIMEOUT = 28    'The DDE transaction could not be completed because the request timed out.
Private Const SE_ERR_DLLNOTFOUND = 32    'The specified DLL was not found.
Private Const SE_ERR_FNF = 2    'The specified file was not found.
Private Const SE_ERR_NOASSOC = 31    'There is no application associated with the given file name extension. This error will also be
                                     '  returned if you attempt to print a file that is not printable.
Private Const SE_ERR_OOM = 8    'There was not enough memory to complete the operation.
Private Const SE_ERR_PNF = 3    'The specified path was not found.
Private Const SE_ERR_SHARE = 26    'A sharing violation occurred.

'OpenURL6 "https://www.google.ca"
'OpenURL6 "C:\Users\Microsoft\Documents\Test.pdf"
'OpenURL6 "C:\Users\Microsoft\Documents\Image.jpg"
'Opens using Microsoft Edge Browser
Public Sub OpenURL6(ByVal sURL As String)
    Dim lRetVal               As Long

    '    lRetVal = ShellExecute(0, "open", sURL)
    'action can be: edit, explore, find, open, print, runas
    lRetVal = ShellExecute(0, "open", "shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", sURL, "", SW_SHOWNORMAL)
    Select Case lRetVal
        Case Is > SE_ERR_DLLNOTFOUND    'If the function succeeds, it returns a value greater than 32
            'Success
        Case ERROR_FILE_NOT_FOUND
            MsgBox "File not found"
        Case ERROR_PATH_NOT_FOUND
            MsgBox "Path not found"
        Case ERROR_BAD_FORMAT
            MsgBox "Bad format."
    End Select
End Sub

Using Internet Explorer Automation

As pointed out below in the comments section by Jason, we can actually use Internet Explorer automation to open Edge to a given URL. Here is a cleaned up version of the code:

Sub OpenURL7(ByVal sURL As String)
Dim oIE As Object

Set oIE = CreateObject(“InternetExplorer.Application”)
With oIE
.Visible = False
.Navigate (“microsoft-edge:” & sURL)

Do While .ReadyState = 4
DoEvents
Loop

.Quit
End With

Set oIE = Nothing
End Sub

I’m still not a huge fan of this approach because now we have to first load IE for it to dispatch the necessary command to load Edge. So we’re loading 2 apps when we’re only after the 2nd one, so it’s just not very efficient.

Also, in my testing, I noticed hanging IE objects, this is why I added code to quit which seems to have resolved that issue.

Let’s Talk VBA Edge Automation!

This is going to be a very brief discussion as unlike the previous browser (Internet Explorer), Microsoft has not exposed Edge to VBA automation. We cannot bind to it and manipulate the DOM, perform web scrapping, … So for any automation, you must still rely on using Internet Explorer! (Told you it would be a brief conversation)

Alternative To Automating Edge Directly
The only way that I know of that you can use to perform automation with Edge, and other major browsers is to turn towards something like:

Other Resources

Page History

Date Summary of Changes
2020-04-30 Initial Release
2020-08-02 Added Let’s Talk VBA Edge Automation!
2022-05-04 Added comment regarding Selenium directly in the article rather than just in the comments.

32 responses on “VBA – Exploring Microsoft Edge

  1. Danny Sanders

    Isn’t there a way to use Chrome embedded inside an Access window. Nowerdays with all the api connections to other apps and programs in the cloud. It would help a lot for automation to have Chrome be opened inside Access. I was thinking aboutt misleading Windows by connecting all the ms explorer register keys to Chrome. So the system is thinking it’s opening explorer. Probably a foolish thougt. But to extend the lifetime of MsAccess it’s important to find a way to connect it better to the internet and subsequently (sorry i am Dutch)) to other modern Apps out there. It would also great to open Excel or Sheets embedded inside Access..

  2. garry

    is there a way to open in a new window the page? both method open page in a new tab if there is an opened edge window.

    1. Daniel Pineault Post author

      No, not to my knowledge.

      Edge is a nightmare to work with in any shape or form! Microsoft has missed the boat, again! Completely ignoring any developer needs.

      You can’t perform any true automation, navigate, explore the respone, DOM, … NOTHING is possible with Edge!

      Your option is Internet Explorer or look into something like Selenium

  3. Gerald Wilkins

    I too was looking for a way to launch Edge using VBA. I knew if you used the Internet Explorer browser that Edge would run, so I just made Edge my default browser and now it launches from Excel using VBA. I found several subroutines that use InternetExplore.Application to launch Internet Explorer; however, I am not able to locate a similar name for Microsoft Edge (Edge.Application).

    1. Daniel Pineault Post author

      To my knowledge, none exist. Since it is not ‘automatible’, it make sense that you can’t initiate its object in that manner. You have to use one of the methods that I demonstrate in this post instead.

  4. Mike

    Do you know a way to access the cookies set by edge by the use of vba?
    I‘d like to establish a communication between a java script / html file and vba.
    The idea is to click on items in the displayed webbrowser html file and to write out the name of the clicked item into a cookie. Then, I‘d like to read out the cookie with vba and process the data related to the items name further..
    (I know, I could also do it with a server side language such as PHP. But I wanted to have it simple and not to install xamp or other tools.)

  5. Jesper Schumacher

    Hi
    Thanks for sharing, but
    I have tried this method with
    objShell.ShellExecute “microsoft-edge:https://dr.dk
    but i get this error “windows cannot access the specified device path or file, you may not have the permission…….”, on my collages PC but nor on my own, we are in the same company and should have same permissions, programs etc.

    Any help would be appriciated.

    BR Jesper

    1. Daniel Pineault Post author

      Without seeing all your code it is hard to say where the issue lies. My code uses simple Shell, not ShellExecute. No need for extra Objects, APIs, …

      If I use

      Public Sub OpenURL5(ByVal sURL As String)
          Dim sCmd                  As String
       
          sCmd = "start microsoft-edge:" & sURL
          shell "cmd /c """ & sCmd & """", vbHide
      End Sub

      and then call it by simply doing

      OpenURL5 "https://dr.dk"

      It works fine for me.

      You might also try using the www. prefix to see if that makes any difference.

      OpenURL5 "https://www.dr.dk/"
      1. Jason

        more simple….

        Sub openweb()

        Set IE = CreateObject(“InternetExplorer.Application”)
        Application.ScreenUpdating = False

        With IE
        IE.Visible = False
        ‘Navigate to this web site
        IE.navigate (“microsoft-edge:https://www.google.com“)

        End With

        End Sub

        1. Daniel Pineault Post author

          Not sure it is simpler than Shell, but definitely good to know about. One more for the toolbox. Thank you for sharing.

          Also, for anyone else, Application.ScreenUpdating is an Excel thing and will err if used in other apps.

          So we should probably clean things up slightly to give us:

          Sub openweb(ByVal sURL As String)
          Dim oIE As Object

          Set oIE = CreateObject("InternetExplorer.Application")
          With oIE
          .Visible = False
          .Navigate ("microsoft-edge:" & sURL)
          End With

          Set oIE = Nothing
          End Sub

  6. Bernd

    Hi there,
    is there a way to close microsoft edge or one of the open tabs using vba?
    greets from germany

  7. Krishna

    Hi Daniel,

    How are you.

    Do you know of a way where one could skip the Internet Explorers annoying FILE SAVE DIALOG option ( OPEN,SAVE,CANCEL) during file download while using Excel VBA Automation. It is proving to be frustrating to get past this final step before completing a download unlike Chrome or Edge where it is smooth and automatically downloads to your DOWNLOAD folder.The option URLFileToDownload is not useful in my case as it involves filling up a form and submitting it to a CGI Script by http POST and then receiving a reply in the form of Downloaded filed whos URL I dont know.

    Thank you

  8. Basil Kubba

    With regard to capturing the Document Object Model (DOM) using MS Edge.

    I initially wrote a VBA macro to drill DOM data from Internet Explorer (IE). As I recently had problems with IE, I switched to MS Edge using the following code to read the DOM that someone put on the web.

    Sub GetDocument(URL As String, DOM As Object)
    Dim XMLPage As New MSXML2.XMLHTTP60
    Dim HTMLDoc As New HTMLDocument

    XMLPage.Open “GET”, URL, False
    XMLPage.send
    HTMLDoc.body.innerHTML = XMLPage.responseText
    Set DOM = HTMLDoc
    End Sub

    Once I got the DOM the rest of my code worked well, and in fact it speeded up as I did not invoke MS Edge, I just internal function that accesses the DOM directly.

    However, if you want to change the MS Edge page properties then I have no ide how you would do that.

    Hope this is useful, regards.

  9. Daniel

    The best and easy way I found was:
    Sub Internet( )
    DIM Hlink as String
    Hlink = “www.websitethatIwanttoopen.com”
    ActiveWorkbook.FollowHyperlink (Hlink)
    End Sub

    ‘With this instruction, doesn´t matter what is your main internet navigator. VBA will open the website without problems.

  10. Same

    Hi Daniel,
    I have vb code which is integrated in outlook (ribbon) to open IE with prefilled user data. how to achieve same in edge?
    Sub IE_Alert()

    Dim IntExpl As Object
    Set IntExpl = CreateObject(“InternetExplorer.Application”)
    Dim dd As Object
    Dim dd2 As Object
    Dim dd3 As Object

    With IntExpl
    .navigate “https://www.website.com/home.aspx?ReturnUrl=%2fpio%2fPost.aspx”
    .Visible = True
    Do Until IntExpl.ReadyState = 4
    Loop
    Set dd = .Document.getElementByID(“ctl00_mainBody_entryCode”)
    dd.Value = “xxxxx”
    Set dd2 = .Document.getElementByID(“ctl00_mainBody_login_UserName”)
    dd2.Value = “xxxxx”
    Set dd3 = .Document.getElementByID(“ctl00_mainBody_login_Password”)
    dd3.Value = “xxxxx”

    End With
    End Sub

  11. Asaf S

    Hi Daniel,
    If you change in Sub OpenURL5
    from sCmd = “start microsoft-edge:” & sURL
    to sCmd = “start msedge ” & sURL
    It will work on file as well (: Something like
    Public Sub OpenURL6(ByVal sURL As String)
    Dim sCmd As String
    sCmd = “start msedge ” & sURL
    shell “cmd /c “”” & sCmd & “”””, vbHide
    End Sub

  12. Eric

    Nightmare on EDGE 🙂 !

    Just like many people, I’m trying to convert my VBA code I had automated years ago on IE to PRINT.

    I “just” have a list of webpages (in my excel file) that I want to open and print to pdfcreator

    It looks like you have a solution but I’m unable to adapt it.

    In your post, you wrote :
    ————————————————————————
    ‘action can be: edit, explore, find, open, PRINT, runas
    lRetVal = ShellExecute(0, “open”, “shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge”, sURL, “”, SW_SHOWNORMAL)
    ————————————————————————

    How can I adapt it to get the “print action” I’m looking for ?

    Thanks a lot !

    Eric

    1. Daniel Pineault Post author

      You’re fighting a loosing battle when it comes to Edge.

      You can in effect use Shell execute to open a URL in Edge, as shown, but switching to use the “print” action results in an “Error 31 – There is no application associated with the given file-name extension.” Microsoft has done everything possible to complicate Edge automation.

      You’ll need to explore Selenium, WebDriver, Chrome Devtools Protocol (CDP), …

  13. eric

    Thanks for your help !
    Unfortunately my company will not allow anything else but EDGE on my computer…

    So I think I have to give up and forget all the automations I had developped.

    So sad

    Thanks

  14. Andres Rios

    Hi Daniel, thank you for a great article. After reading it carefully, together with all questions and Answers, I have a quick question. in case you know the answer:
    I have an excel workbook with a Vba Macro that is able to use Selenium by downloading, installing, then adding Selenium Type Library to Vba References.
    However, I send the excel workbook to another user and it doesn’t work. In the past, once I added the Microsoft HTML Object Library to an Excel Workbook, it worked when I distributed the Excel to final users. Now, I’m agraid each and every user would need to download, install Selenium, replace/update the Web Browser Driver in Selenium and Add the Selenium Type Library, which would be a total nightmare.
    How familiar are you with using Selenium from excel VBa and/or do you know if each and every final user will need to download and install Selenium?

    Thank you

    1. aj morales

      Andres,
      The Selenium methos forces all downline PCs to also have the Selenium Basic installed AND the appropriate WebDriver version! This gets nasty when all users are not on the same version of Edge, Chrome etc. In my solution, I created a ZIP file with the Selenium Basic file And a few versions of the WebDrivers in strategic folders. Then a macro was written to identify the web browser version and then copy/past the correct WebDriver file to the appropriate Selenuim Basic folder. This gets nasty again as users update their browser versions!!!!

  15. René

    Hi! I have a heavily used Excel sheet with some VBA. The Excel is downloaded via a button on a SharePoint page. In IE everything works fine. Now we’re moving to Edge (organisation policy) and my VBA generates errors (first fail Error 1004 on this basic command: ActiveSheet.Name = “RISK_ACTION”). What I see is in IE the sheet is downloaded to the local computers Download folder. In Edge it isn’t, the sheet is executed in Excel right away. Do you have any idea what Edge does and why this behaviour results in errors in Excel?

  16. Labrys

    I had to change
    Public Declare Function ShellExecute
    to
    Public Declare PtrSafe Function ShellExecute
    else it brings up an error about 64 bit systems

  17. audeser

    Hi Daniel,
    I want you to take a look at code posted by user Kevin Yeung @ https://learn.microsoft.com/en-us/answers/questions/829365/vba-automation-with-edge-ie-mode.html

    I have ammended code, but, despite I’m quite skilled with VBA I still could not make this run (… I have to work out what is missing with the strHwndIEs variable). In that post another user also posted he made progress not using IE-mode, but he has not yet shared the code. My ammened code looks like:

    ' https://learn.microsoft.com/en-us/answers/questions/843285/edge-opening-and-filling-a-webpage-through-vba.html
    ' https://learn.microsoft.com/en-us/answers/questions/829365/vba-automation-with-edge-ie-mode.html
    ' https://tmaxdialer.com/bill/index.php/knowledgebase/490/Session-Expired---using-Microsoft-Edge.html (to keep cookies active)
    
    ' There are two solutions to achieve automation on Edge browser:
    ' 1) SeleniumBasic or 2) Win API.
    ' Though SelenimBasic seems to be the mainstream suggestion at forums,
    ' Win API can be regarded as better solution in several different ways:
    '    Pros of Win API Solution :
    '    - No need installation and regular update of Edge driver.
    '    - Able to automate with multiple existing Edge browser windows (which have been opened before program start).
    '    - Most of codes in existing IOM solution can be preserved and re-applied. It is because both solutions of IOM and Win API should use HTML Document Object Model (DOM) at last to achieve automation on webpage. The difference is on the way to find browser and attain HTMLDocument from browser.
    '
    '    Cons of Win API Solution :
    '    - We can automate with “webpage” on Edge browser but not the “Edge browser” itself. It is not like IOM and SeleniumBasic that can control web browser. For this, I use Shell function and DOS commands to achieve automation of opening and closing Edge browser.
    '    - The webpage has to be opened in IE mode at Edge browser which means this solution is subject to Microsoft’s future direction on IE mode of Edge browser.
    
    Option Explicit
    
    'ToDo: If I use late binding, docHTML will never know it should be instantiated as a HTMLDocument, so, in some part of the code may this line be necessary:  Set docHTML = CreateObject("MSHTML.HTMLDocument")
    
    'Part 1 --- Locate IES
    Private strHwndIEs As String ' this is always empty... should work it out what is happening here
    Private lngHwndIndex As Long ' should this be converted to LongPtr?
    Public Declare PtrSafe Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As LongPtr, ByVal lParam As Long) As Long
    Public Declare PtrSafe Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As LongPtr, ByVal lpEnumFunc As LongPtr, ByVal lParam As Long) As Long
    Public Declare PtrSafe Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
           
    'Part 2 --- Get HTMLDocument from IES
    Private Const SMTO_ABORTIFHUNG = &H2
    Private Const GUID_IHTMLDocument2 = "{332C4425-26CB-11D0-B483-00C04FD90119}"
    Public Declare PtrSafe Function RegisterWindowMessage Lib "user32.dll" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
    Public Declare PtrSafe Function SendMessageTimeout Lib "user32.dll" Alias "SendMessageTimeoutA" (ByVal hWnd As LongPtr, ByVal msg As Long, ByVal wParam As Long, lParam As Any, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
    Public Declare PtrSafe Function IIDFromString Lib "ole32.dll" (lpsz As Any, lpiid As Any) As Long
    Public Declare PtrSafe Function ObjectFromLresult Lib "oleacc.dll" (ByVal lResult As Long, riid As Any, ByVal wParam As Long, ppvObject As Any) As Long
              
    'Part 3 --- Check Process Name
    Public Declare PtrSafe Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As LongPtr, lpdwProcessId As Long) As Long
    
    '1) Place the following codes in a new blank module. I name this module as “MsEdge” usually. The codes in this module are no need to modify for usage. You can directly use the codes even if you don’t know much about Win API.
    Public lngProcessID_Close As Long
       
    Public Function findEdgeDOM(Title As String, Url As String) As Object 'As MSHTML.HTMLDocument
    ' Find criteria-hitting Edge page in IE mode
        
        Dim hwndIEs As Long
                   
        Do
            hwndIEs = EnumHwndIEs
                       
            If hwndIEs Then
                Set findEdgeDOM = getHTMLDocumentFromIEs(hwndIEs)
                If Not findEdgeDOM Is Nothing Then
                    If VBA.InStr(findEdgeDOM.Title, Title) * VBA.InStr(findEdgeDOM.Url, Url) Then
                        Do
                            hwndIEs = EnumHwndIEs
                        Loop While hwndIEs
                   
                        Exit Function
                    Else
                        Set findEdgeDOM = Nothing
                    End If
                End If
            End If
        Loop While hwndIEs
    End Function
       
    Public Function EnumHwndIEs() As Long
    ' Get all hwnds of IEs
        If VBA.Len(strHwndIEs) = 0 Then
            EnumWindows AddressOf EnumWindowsProc, 0
            lngHwndIndex = 0
        End If
           
        ' Exit function when overflow
        If lngHwndIndex + 1 > (VBA.Len(strHwndIEs) - VBA.Len(VBA.Replace(strHwndIEs, ",", ""))) Then
            EnumHwndIEs = 0
            strHwndIEs = ""
            Exit Function
        End If
           
        ' Return IES hwnd one by one
        EnumHwndIEs = VBA.CLng(VBA.Split(VBA.Left(strHwndIEs, VBA.Len(strHwndIEs) - 1), ",")(lngHwndIndex))
        lngHwndIndex = lngHwndIndex + 1
    End Function
       
    Private Function EnumWindowsProc(ByVal hWnd As LongPtr, ByVal lParam As Long) As Boolean
        Dim lngProcessID As Long
                   
        GetWindowThreadProcessId hWnd, lngProcessID
        EnumChildWindows hWnd, AddressOf EnumChildProc, lngProcessID
        EnumWindowsProc = True
    End Function
       
    Public Function EnumChildProc(ByVal hWnd As LongPtr, ByVal lParam As Long) As Boolean
        Dim strTargetClass As String
        Dim strClassName As String
                   
        strTargetClass = "Internet Explorer_Server"
               
        strClassName = getClass(hWnd)
           
        If strClassName = strTargetClass Then
            If GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process WHERE ProcessId='" & lParam & "' AND Name='msedge.exe'").Count Then
                strHwndIEs = strHwndIEs & hWnd & ","
                lngProcessID_Close = lParam
                EnumChildProc = False
                Exit Function
            End If
        End If
               
        EnumChildProc = True
    End Function
       
    Private Function getClass(hWnd As LongPtr) As String
        Dim strClassName As String
        Dim lngRetLen As Long
           
        strClassName = VBA.Space(255)
        lngRetLen = GetClassName(hWnd, strClassName, VBA.Len(strClassName))
        getClass = VBA.Left(strClassName, lngRetLen)
    End Function
       
    Public Function getHTMLDocumentFromIEs(ByVal hWnd As LongPtr) As Object 'MSHTML.HTMLDocument
        Dim iid(0 To 3) As Long
        Dim lMsg As Long, lRes As Long
           
        lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
        SendMessageTimeout hWnd, lMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes
       
        If lRes Then
            IIDFromString StrPtr(GUID_IHTMLDocument2), iid(0)
            ObjectFromLresult lRes, iid(0), 0, getHTMLDocumentFromIEs
        End If
    End Function
       
    Public Sub closeEdge(Title As String, Url As String)
    ' Close a Edge browser (the last one in EnumWindows order) with criteria-hitting webpage
           
        lngProcessID_Close = 0
       
        Dim findEdgeDOM As Object
        Dim hwndIEs As LongPtr
                   
        Do
            hwndIEs = EnumHwndIEs
                       
            If hwndIEs Then
                Set findEdgeDOM = getHTMLDocumentFromIEs(hwndIEs)
                               
                If VBA.InStr(findEdgeDOM.Title, Title) * VBA.InStr(findEdgeDOM.Url, Url) Then
                    Shell "TaskKill /pid " & lngProcessID_Close
                       
                    Do
                        hwndIEs = EnumHwndIEs
                    Loop While hwndIEs
                   
                    Exit Sub
                End If
            End If
        Loop While hwndIEs
    End Sub
    
    '-----------
    
    Public Sub findEdgeDOM_DemoProc()
    ' Demo Proc : Use findEdgeDOM Function to get DOM of specific Edge webpage by Title AND URL
               
        Dim docHTML As Object 'MSHTML.HTMLDocument
        Dim Url As String
        Dim WebPagTitle As String
        
        Url = "google.com" 'VBA.InputBox("Input Webpage URL Here", , "google.com")
        WebPagTitle = VBA.InputBox("Enter part of webpage title here", , "")
        Set docHTML = findEdgeDOM(WebPagTitle, Url)
        
        ' You can fill just one argument with either part of webpage title or URL as keyword to search for the target browser and leave another one blank (“”).
        ' If you provide both title and URL, the funcitons return DOM of the only browser that meets both criteria.
        If Not docHTML Is Nothing Then Debug.Print docHTML.Title, docHTML.Url
    End Sub
       
    Public Sub goEdge()
    ' Go through every Edge webpage (opened in IE mode) and print out hwndIES, webpage Title & webpage URL
       
        Dim hwndIEs As LongPtr
        Dim docHTML As Object ' MSHTML.HTMLDocument
    
        Do
            hwndIEs = EnumHwndIEs
            If hwndIEs Then
                Set docHTML = getHTMLDocumentFromIEs(hwndIEs)
                
                'If MsgBox("This one? " & vbCrLf & docHTML.Title, vbYesNo) = vbYes Then
                '    Do
                '        hwndIES = enumHwndIES
                '    Loop While hwndIES
                '    Exit Do
                'Else
                '    Set docHTML = Nothing
                'End If
        
                Debug.Print hwndIEs, docHTML.Title, docHTML.Url
            End If
        Loop While hwndIEs
        
        If docHTML Is Nothing Then
            MsgBox "No Edge", vbCritical
            Exit Sub
        End If
    End Sub
       
    Public Sub openURL_DemoProc()
    ' Open URL on Edge
        Dim Url As String
        
        Url = VBA.InputBox("Input Webpage URL Here", , "google.com")
        Shell VBA.Environ("ProgramFiles(x86)") & "\Microsoft\Edge\Application\msedge.exe -url " & Url, vbNormalFocus
        'Shell "cmd /c ""start microsoft-edge:" & Url & """, vbNormalFocus
    End Sub
       
    Public Sub closeEdge_DemoProc()
        Dim Url As String
        Dim WebPageTitle As String
        
        WebPageTitle = "Google" 'vba.InputBox("Enter Webpage Title Here", , "")
        Url = "https://www.google.com/" 'vba.InputBox("Enter URL Here", , "")
        closeEdge WebPageTitle, Url
    End Sub
    

    Any other eyes looking at this are wellcome!