Excel VBA userform open hyperlink with a button

3k views Asked by At

I have a userform which I input information into, one of the inputs are called webpage and I want to open the webpage for each item I input into the userform when I click a command button.

Sheets("Data").Range("DataStart").Offset(TargetRow, 10).Value = Webpage

MyForm.Webpage = Sheets("Data").Range("DataStart").Offset(TargetRow, 10).Value

I am trying to use follow.hyperlink

Private Sub Webpage_Click()

Dim webpage As String
Set webpage = MyForm.Webpage = Sheets("Data").Range("DataStart").Offset(TargetRow, 10).Value

ActiveWorkbook.FollowHyperlink Address:="webpage"

End Sub

This doesn´t work.

2

There are 2 answers

0
Tim Williams On BEST ANSWER
 ActiveWorkbook.FollowHyperlink Address:=webpage

no quotes

0
ComradeMicha On

You can also use the Shell to open a specific browser, if required:

Sub Open_HyperLinks()
Dim browserPath As String
Dim linkURL As String

browserPath = Environ("PROGRAMFILES(X86)") & "\Mozilla Firefox\firefox.exe"
linkURL = Cells(1, 1).Value

Shell browserPath & " -url " & linkURL
End Sub