2016-08-30 124 views
0

我正在使用的工作簿用于项目跟踪。在开始页面上,这是当前的&即将推出的项目页面。当你按下一个表格控制按钮时,它执行下面的代码。以下代码所做的是读取工作簿中的每张工作表(有30张),然后是A5中所有具有值“Project#:”的工作表。当它具有该值时,它将把指定的值放入指定的行和列中。开始时带“**”的行是不起作用的行。下面带“*”的行是我暂时使用的,但没有超链接,只是表名。Excel VBA代码超链接到其他工作表

我想在代码中发生下面就是让行“A”包含的表名作为文本和超链接到表

For Each ws In ThisWorkbook.Worksheets 
      If ws.Range("A5") = "Project # :" And ws.Range("E16") = "" Then 
       x = .Range("B" & Rows.Count).End(xlUp).Offset(1).row 

       **.Cells(x, "A").Formula = "=ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _'" & ws.Name & "'" 
       *.Cells(x, "A").Value = ws.Name 'classifying number 

       .Cells(x, "B").Formula = "='" & ws.Name & "'!$B$5" 'Project # 
       .Cells(x, "C").Formula = "='" & ws.Name & "'!$A$1" 'Project Name 
       .Cells(x, "D").Formula = "='" & ws.Name & "'!$B$8" 'Project Engineer 
       .Cells(x, "E").Formula = "='" & ws.Name & "'!$B$11" 'In-service Due 
       .Cells(x, "F").Formula = "='" & ws.Name & "'!$E$6" '30% Due 
       .Cells(x, "G").Formula = "='" & ws.Name & "'!$F$13" '30% Success 
       .Cells(x, "H").Formula = "='" & ws.Name & "'!$E$7" '60% due 
       .Cells(x, "I").Formula = "='" & ws.Name & "'!$F$14" '60% Success 
       .Cells(x, "J").Formula = "='" & ws.Name & "'!$E$8" '90% due 
       .Cells(x, "K").Formula = "='" & ws.Name & "'!$F$15" '90% Success 
       .Cells(x, "L").Formula = "='" & ws.Name & "'!$E$5" 'Material Forecast due date 
       .Cells(x, "M").Formula = "='" & ws.Name & "'!$F$11" 'Materials Forecast Success 
       .Cells(x, "N").Formula = "='" & ws.Name & "'!$B$15" 'Non Stores Items 
       .Cells(x, "O").Formula = "='" & ws.Name & "'!$B$16" 'Non Stores Items Ordered on time 
       .Cells(x, "P").Formula = "='" & ws.Name & "'!$A$17" 'Non Stores Items Success 
      End If 
     Next 

    End With 

回答

0

而不是

.Cells(x, "A").Formula = "=ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _'" & ws.Name & "'" 

使用

.Hyperlinks.Add Anchor:=.Cells(x, "A"), _ 
       Address:="", _ 
       SubAddress:= "'" & ws.Name & "'!A1", _ 
       TextToDisplay:= ws.Name 

我假设您的代码正在With ActiveSheet(或等同ent)块。

+0

这是完美的!我一直试图弄清楚这一点,非常感谢你! –

相关问题