指向新工作簿的超链接不起作用



我是Excel的新手,所以我希望这是有意义的。下面的代码显示了单击用户窗体上的按钮时在特定工作簿(与当前工作簿分开)上创建的新工作表。但是,我指向在单独工作簿上创建的工作表的超链接似乎已损坏。我做错了什么?有什么帮助,谢谢!

Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Employee Information")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
If Me.cbStores.Value = "Northern" Then
Dim newWB As Workbook
Dim thisWB As Workbook
Set thisWB = ThisWorkbook
Set newWB = GetOrCreateWB("EmployeeTemplates", "C:Users...Folder") '<--| Opening EmployeeTemplates wb
thisWB.Sheets("Template").Copy after:=newWB.Sheets(1)
With ActiveSheet '<--| the just pasted worksheet becomes the active one
.Name = AddEmployeeUF.txtFirstname.Text + AddEmployeeUF.txtMiddleinitial.Text + AddEmployeeUF.txtLastname.Text + "Template" '<--| Name it
ws.Hyperlinks.Add Anchor:=ws.Range("F" & LastRow), Address:="", SubAddress:=.Name & "!A1", TextToDisplay:="View" '<--| hyperlink to new sheet
End With
End If

您需要在地址Address:=newWB.Path & "" & newWB.Name中指定工作簿路径和名称。要确保在工作表名称中使用空格时不会失败,请将此空格用于子地址SubAddress:="'" & .Name & "'!A1"

这应该是正确的方法。

ws.Hyperlinks.Add Anchor:=ws.Range("F" & LastRow), Address:=newWB.Path & "" & newWB.Name, SubAddress:="'" & .Name & "'!A1", TextToDisplay:="View" '<--| hyperlink to new sheet

最新更新