Adding Hyperlinks via Userform

FlavorFlav

New Member
Joined
Mar 29, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I was really happy that I finally were able to manage UserForms properly, but in the end there was still a problem :)

UseCase: The user can click on a button & then input the data (hyperlink, Description, Text to display). This hyperlink is then shortly checked with an URL existance function, which works great.

However, everything works but when I then try to open the added Hyperlink in the Excel, it does not work at all... Can somebody help me there and show me where the mistake is?

Step 1: Click on Button

1681927541921.png


Step 2: User Form appears & link is tested with an URL existance function:
1681927590328.png


Step 3: "Link", "Text to Show" & "Description" is added to the Excel table (See screenshot 1). The user should then click on the link in Excel & open the link. But if I hoover then over the link in the Excel the following is shown & by clicking on it, it appers the error message below.

1681927949199.png
1681928019109.png



The code is the following:

Sub Button_New_Click()

Dim LastRow As Integer
Dim IsEmpty1, IsEmpty2 As Boolean

Range("T_Links_" & ActiveSheet.Range("B3")).Select 'Refers to table Name with links on the corresponding project

IsEmpty1 = IsEmpty(Selection.Cells(1, 1))
IsEmpty2 = IsEmpty(Selection.Cells(2, 1))

If IsEmpty1 = False Then 'to check if first cell is filled with data in Links-Table
If IsEmpty2 = False Then 'to check if second cell is filled with data in Links-Table (if only first is filled, still an adjustment needed)
LastRow = Selection.End(xlDown).Row + 1
Else
LastRow = Selection.Cells(2, 1).Row
End If
Else
LastRow = Selection.Cells(1, 1).Row
End If

Range("A" & LastRow).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=Input_Hyperlink.Value, TextToDisplay:=Input_TextShow.Value
Selection.Offset(0, 1).Value = Input_Description

Unload Me

End Sub

If I use the "Immediate Window" , it shows me that "Input_Hyperlink" is a String & also that "Input_Hyperlink.Value" = "www.google.com" , but in the Excel itself it shows then not "www.google.com" but instead a longer text as shown in the screenshot above, which results in an error message...

Any ideas why this error appears?

Thanks in advance!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I finally found the mistake :) "Http:/" needed to be added in front of the address.

ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="http:/" & Input_Hyperlink.Value, TextToDisplay:=Input_TextShow.Value

Lost around 4 hours today for this but at least it is working ;)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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