使用用户窗体上的文本框和指定的路径创建超链接

Create Hyperlink using textbox on UserForm and Path specified

我有一个 table 供用户使用 UserForm 导入新的 info/data。

我希望用户输入文档名称,因为文件没有正确标记(我不太关心)我希望文本框成为超链接的标签,路径由用户将文件移动到适当的文件夹后。

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

这条线路最初有效

    .Range(13) = txtDrawings.Value

现在我需要那个值,当添加为超链接时。我试过这个...

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

还有这个……

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

End With

End Sub

这对我有用

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. 删除代码中 Anchor: 之前的括号。同时删除任何 On Error Resume Next。现在试试上面的
  2. 删除行 Dim Label17 As StringDim txtDrawing As String。这些是控件。