Forum Discussion
Excel VBA and starting URL by clicking Shapes ???
- Apr 17, 2023I think I found the cause for starting in SafeMode - if you start FireFox (or any other browser, I think) while pressing the SHIFT-key the browser is FORCED to start in SafeMode ... that's my problem !
I have to choose another key to press when I want the users to open the link !
As far as I could understand...
It seems like you are having trouble with opening a URL in a browser from an Excel VBA macro when the browser is not already running. One possible solution could be to use the Shell function to open the URL in the default browser.
Here’s an example:
Sub OpenURL(URL As String)
Dim browserPath As String
browserPath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
Shell (browserPath & " " & URL)
End Sub
This code specifies the path to the Internet Explorer browser and uses the Shell function to open the URL. You can modify the browserPath variable to specify the path to a different browser if desired.
You can call this function from your findLinkTilVielsen subroutine like this:
Public Sub findLinkTilVielsen(Sh As Shape)
If Trim(Sh.Hyperlink.Address) = "" Then
visFejlMeddelelse "No link is provided !"
Else
On Error GoTo notOK
OpenURL Sh.Hyperlink.Address
GoTo goAhead
notOK: On Error GoTo 0
visFejlMeddelelse "Link is corrupt !"
goAhead:
End If
End Sub
This should open the URL in the default browser, even if the browser is not already running.
I hope this helps!
I want to use THE DEFAULT browser and NOT Edge ... in my case I use Firefox but it should be posible to just reference 'the default browser' - rigth ?
- NikolinoDEApr 17, 2023Gold Contributor
If you want to open the URL in the default browser for each user, you can use the FollowHyperlink method of the Application object instead of using the Shell function.
Here’s an example:
Sub OpenURL(URL As String) Application.FollowHyperlink URL End Sub
This code uses the FollowHyperlink method to open the URL in the default browser for the current user. You can call this function from your findLinkTilVielsen subroutine like this:
Public Sub findLinkTilVielsen(Sh As Shape) If Trim(Sh.Hyperlink.Address) = "" Then visFejlMeddelelse "No link is provided !" Else On Error GoTo notOK OpenURL Sh.Hyperlink.Address GoTo goAhead notOK: On Error GoTo 0 visFejlMeddelelse "Link is corrupt !" goAhead: End If End Sub
This should open the URL in the default browser for the current user, even if the browser is not already running.
I hope this helps!
I know I don't know anything (Socrates)
- keldsorApr 17, 2023Brass Contributor
???? I don't get you ... I see NO FollowHyperlink in Application !
But I must admit you CAN type it AND compile it without errors, but it wont run - it reports:
Run-time error 438
Object doesn't support this property or method
It seems like I have to use this - it works like I want to:ActiveWorkbook.FollowHyperlink Sh.Hyperlink.Address & "#" & Sh.Hyperlink.SubAddress
UPDATE:
No, this last code change didn't do it either - I still get this message with SafeMode or RESET when the browser is NOT running !
- keldsorApr 17, 2023Brass ContributorI think I found the cause for starting in SafeMode - if you start FireFox (or any other browser, I think) while pressing the SHIFT-key the browser is FORCED to start in SafeMode ... that's my problem !
I have to choose another key to press when I want the users to open the link !