【发布时间】:2017-07-31 01:39:21
【问题描述】:
我是 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
【问题讨论】:
-
您在哪里/如何声明
ws和LastRow?链接是如何“断开”的? -
它只是将我的主页表上的超链接放在一个空白的单元格上。我不认为这是问题所在。它应该链接到单独工作簿上新创建的页面,但它没有。
-
地址为空
-
地址应该包含什么,就像我说我是 Excel 新手
-
LastRow = ws.Range("A" & Rows.Count)应该是LastRow = ws.Range("A" & ws.Rows.Count)...以确保您计算ws上的行数。地址是超链接的地址 - 请参阅this page 了解更多信息。
标签: vba excel hyperlink excel-2010