How to Close Microsoft Edge Webpage(s) Using VBA

2ramsays

New Member
Joined
Nov 27, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I tried searching for a solution but could not locate anything to help. As the subject describes, I would like to run a macro to close specific webpages when I am finished with them while leaving one or more others open. Depending on the webpage, I either download an Excel file from it (if available) or copy and paste information into an existing worksheet. Once I have done that I would like the webpage to close, I assume running a macro to do this would work but I cannot figure out how to do this. I don't have any code to share as I don't know where to begin.

I am using Microsoft 365 with Microsoft Edge Version 107.0.1418.56 (Official build) (64-bit).

Thanks,

Dave
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
See if this helps

It a link from this page
 
Upvote 0
Thank you Zot for pointing me in that direction. I copied and pasted the code into a module and I receive a compile error on Dim uiAuto As CUIAutomation.
I am a novice when it comes to VBA so you are aware of my abilities.

Thanks,

Dave

Sub test()

Dim BrWsr As Variant

Dim uiAuto As CUIAutomation
Set uiAuto = New CUIAutomation

Dim elmRoot As IUIAutomationElement
Set elmRoot = uiAuto.GetRootElement

Dim cndChromeWidgetWindows As IUIAutomationCondition
Set cndChromeWidgetWindows = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "Chrome_WidgetWin_1")
Dim aryChromeWidgetWindows As IUIAutomationElementArray
Set aryChromeWidgetWindows = elmRoot.FindAll(TreeScope_Children, cndChromeWidgetWindows)

Dim wptn As IUIAutomationWindowPattern, i As Integer

Set BrWsr = CreateObject("Shell.Application")

TEST_site = "Yahoo! JAPAN"

Url = "microsoft-edge:" & TEST_site

BrWsr.ShellExecute Url

For i = 0 To aryChromeWidgetWindows.Length - 1
If aryChromeWidgetWindows.GetElement(i).CurrentName Like "*- Microsoft" & ChrW(&H200B) & " Edge" Then
Set wptn = aryChromeWidgetWindows.GetElement(i).GetCurrentPattern(UIA_WindowPatternId)
wptn.Close
End If
Next

End Sub
 
Upvote 0
😅 I was more like just helping you Google 😇

Hope someone out there can give further help. I have yet to study this code
 
Upvote 0
That code requires that you set a reference to the UIAutomationClient library via Tools\References in the VBE.

Sans titre.png
 
Upvote 0
Thank you Jaafar, that allowed the macro to run. However, this closed the entire Edge Browser instead of only closing the one webpage referenced. The first reply from Zot was very helpful but based on the comments on the site provided, this has not been solved. Does anyone know how to one webpage while leaving Edge open with other tabs?

Dave
 
Upvote 0
Thank you Jaafar, that allowed the macro to run. However, this closed the entire Edge Browser instead of only closing the one webpage referenced. The first reply from Zot was very helpful but based on the comments on the site provided, this has not been solved. Does anyone know how to one webpage while leaving Edge open with other tabs?

Dave
Same here. I couldn't successfully close specific tabs with those codes.
Have you considered using the MSAA instead of using IUIAutomation ?
 
Upvote 0
I am a novice or maybe a beginner and I don't know what MSAA is. After using the macro that closes the entire browser I ran it a second time and the macro opened the browser again with my normal tabs plus Google which is part of the code so for now this accomplishes what I wanted to do other than the extra Google tab. I will continue to search for a solution just to see if it can be done. If I find one somewhere I will post here again for others to reference.

Thanks for everyone's help here.

Dave
 
Upvote 0
I am a novice or maybe a beginner and I don't know what MSAA is. After using the macro that closes the entire browser I ran it a second time and the macro opened the browser again with my normal tabs plus Google which is part of the code so for now this accomplishes what I wanted to do other than the extra Google tab. I will continue to search for a solution just to see if it can be done. If I find one somewhere I will post here again for others to reference.

Thanks for everyone's help here.

Dave
MSAA is the legacy accessibility technology. It is less capable of UIAutomation but both technologies share the same principals and both expose information about user interface elements. Also, MSAA is less complicated from a coding perspective.

You can use the MS accessibility insights tool or Inspect for inspecting the UI elements. I will give this a try and post back if anything comes up.
 
Upvote 0
MSAA is the legacy accessibility technology. It is less capable of UIAutomation but both technologies share the same principals and both expose information about user interface elements. Also, MSAA is less complicated from a coding perspective.

You can use the MS accessibility insights tool or Inspect for inspecting the UI elements. I will give this a try and post back if anything comes up.
Thank you for the explanation and attempt.
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,995
Members
449,480
Latest member
yesitisasport

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