VBA code to create a hyperlink from a textbox to a worksheet in a workbook.
Scanadoo646464
Posted messages
16
Status
Member
-
Scanadoo646464 Posted messages 16 Status Member -
Scanadoo646464 Posted messages 16 Status Member -
Hello,
I am looking for a way to activate a hyperlink in a textbox by double-clicking it to an Excel workbook tab. If anyone has any ideas.
Thank you.
Configuration: Android / Chrome 84.0.4147.89
I am looking for a way to activate a hyperlink in a textbox by double-clicking it to an Excel workbook tab. If anyone has any ideas.
Thank you.
Configuration: Android / Chrome 84.0.4147.89
9 answers
-
Hello,
an example:
put the link in cell A1 of the sheet that will open the UserForm
Option Explicit Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) If Range("A1").Hyperlinks.Count > 0 Then If TextBox1.Text = Range("A1").Hyperlinks(1).TextToDisplay Then With Selection.Hyperlinks(1) .Follow NewWindow:=False, AddHistory:=True If .SubAddress <> "" Then Sheets(Split(.SubAddress, "!")(0)).Select Range(Split(.SubAddress, "!")(1)).Select End If End With End If End If End Sub Private Sub UserForm_Initialize() TextBox1.Text = Range("A1").Value End Sub
To adapt
--
@+ Le Pivert -
Hello cs_le pivert !
I'm testing your code and I'll keep you updated. In the meantime, here is my coding. The hyperlink works for Google Maps but not for my workbook.
Dim f, choix(), Rng, Ncol
Private Sub TextBox6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ThisWorkbook.FollowHyperlink link & Me.TextBox6.Text
End Sub
Private Sub TextBox7_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ThisWorkbook.FollowHyperlink link & Me.TextBox7.Text
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set Rng = f.Range("A3:G" & f.[a65000].End(xlUp).Row)
TblTmp = Rng.Value
Ncol = Rng.Columns.Count
For i = LBound(TblTmp) To UBound(TblTmp)
ReDim Preserve choix(1 To i)
For k = LBound(TblTmp) To UBound(TblTmp, 2)
choix(i) = choix(i) & TblTmp(i, k) & " * "
Next k
Next i
Me.ComboBox1.List = Rng.Value
'---
For i = 1 To Ncol
temp = temp & f.Columns(i).Width * 0.8 & ";"
Next
Me.ComboBox1.ColumnCount = Ncol
Me.ComboBox1.ColumnWidths = temp
'-- Headers TextBox
For i = 1 To Ncol
Set Lab = Me.Controls.Add("Forms.Label.1")
Lab.Caption = f.Cells(2, i)
Lab.Top = Me("textbox" & i + 1).Top - 17
Lab.Left = Me("textbox" & i + 1).Left
Next
End Sub
Private Sub comboBox1_Change()
If Me.ComboBox1 <> "" Then
If Me.ComboBox1.ListIndex = -1 Then
mots = Split(Trim(Me.ComboBox1), " ")
Tbl = choix
For i = LBound(mots) To UBound(mots)
Tbl = Filter(Tbl, mots(i), True, vbTextCompare)
Next i
n = 0: Dim b()
For i = LBound(Tbl) To UBound(Tbl)
a = Split(Tbl(i), "*")
n = n + 1: ReDim Preserve b(1 To Ncol, 1 To n)
For k = 1 To Ncol
b(k, i + 1) = a(k - 1)
Next k
Next i
If n > 0 Then
ReDim Preserve b(1 To Ncol, 1 To n + 1)
Me.ComboBox1.List = Application.Transpose(b)
Me.ComboBox1.RemoveItem n
End If
Me.ComboBox1.DropDown
Else
For k = 0 To Ncol - 1
Me("textBox" & k + 2) = Me.ComboBox1.Column(k)
Next k
End If
End If
End Sub-
-
The hyperlink works for Google Maps but not for my spreadsheet.
It's not the same procedure for internal links within the spreadsheet.
See this discussion with a downloadable spreadsheet
https://codes-sources.commentcamarche.net/forum/affich-10101612-lancement-d-un-lien-hypertexte-avec-une-macro?page=2#45
@+ -
-
-
-
-
Thank you very much for the procedure ... I missed a step!
https://www.cjoint.com/c/JGCrqKkoHDj -
I have carefully examined your code. It's perfect and exactly what I need, but I can't adapt it. I want to keep the intuitive search in my combo box, and I don't know how to do that...
-
Hello Le Pivert. Thank you for your research.
I have a runtime error 9 when launching the dblclick. Should I change the way I display my hyperlinks?-
It works for me. It's not the links, we don't use them!
Only TextBox 7 needs to be modified
I have a runtime error 9
to fix, put this:
Private Sub TextBox7_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim sheet As String If TextBox7.Text = "" Then Exit Sub sheet = Split(TextBox7.Text, "'")(0) Sheets(sheet).Activate End Sub
@+
-
-
Well, I just can't understand this... it's not working for me!!!
-
strange ... I'm checking this out while verifying everything! I'll keep you updated.
thanks a lot for the help!!! -
Well, I'm sorry... nothing works. I'll try on another machine just in case...
-

