I have an Edge browser open with one tab. I want to get the URL of the webpage into a variable in excel so I can create a hyperlink to it. I asked this question a couple years ago and received an answer that only works once. If I then navigate to a different webpage and run the macro, it pulls up the URL of the previous page, not the open one.
Function TryGetUrl(ByRef outUrl As String) As Boolean
On Error GoTo errExit
' change to "Chrome" if desired
AppActivate "Edge", True
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys "^l^c", True
Application.Wait Now + TimeSerial(0, 0, 1)
AppActivate Application.Caption
' needs a reference to the 'Microsoft Forms 2.0 Object Library'
With New MSForms.DataObject
.GetFromClipboard
outUrl = .GetText
End With
TryGetUrl = True
Exit Function
errExit:
End Function
New contributor
Steven Thomasson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.