我是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
答案 0 :(得分:0)
您需要在地址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