Kenny
Kenny

Reputation: 353

Create Hyperlink using textbox on UserForm and Path specified

I have a table for users to import new info/data onto, using a UserForm.

I would like the User to type the document name because the File is not labeled correctly (which I don't care much about) I would like the textbox to be the label for the hyperlink and the Path be selected by the user after they've moved the file into it's appropriate folder.

Private Sub cmd_ADD_Click()
    'Copy input values to table2.
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Table2")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
Dim Label17 As String
Dim txtDrawing As String

With newrow

this line worked originally

    .Range(13) = txtDrawings.Value

now I need that value, when added to be a hyperlink. I tried this...

    .Range(13).Hyperlinks.Add(Anchor:=.Range(13), _
      Address:=Label17, _
      ScreenTip:="DRAWING", _
      TextToDisplay:=txtDrawings.Value)

and this...

    .Range(13) = .Hyperlinks.Add(Label17, Me.txtDrawings.Value)

End With

End Sub

Upvotes: 2

Views: 2385

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149335

This worked for me

Dim ws As Worksheet
Set ws = ActiveSheet

Dim tbl As ListObject
Set tbl = ws.ListObjects("Table1")

Dim newrow As ListRow
Set newrow = tbl.ListRows.Add

With newrow
    .Range(13).Hyperlinks.Add Anchor:=.Range(13), _
                              Address:=Label17.Caption, _
                              ScreenTip:="DRAWING", _
                              TextToDisplay:=txtDrawings.Value
End With
  1. Remove the brackets before Anchor: in your code. Also remove any On Error Resume Next. Now try the above
  2. Delete the lines Dim Label17 As String and Dim txtDrawing As String. Those are controls.

Upvotes: 2

Related Questions