2017-07-19 173 views
0

我知道如何使用指定工作簿中所有工作表的特定超链接来填充工作表,但如何排除某些工作簿被列出?在excel中创建超链接列表

我已经列出了我以前使用的VB。我想排除某些表,如“测试结果”等

Sub GetHyperlinks() 
    Dim ws As Worksheet 
    Dim i As Integer 

    i = 9 

    For Each ws In ThisWorkbook.Worksheets 
     ActiveWorkbook.Sheets("overview").Hyperlinks.Add _ 
     Anchor:=ActiveWorkbook.Sheets("overview").Cells(i, 1), _ 
     Address:="", _ 
     SubAddress:="'" & ws.NAme & "'!A1", _ 
     TextToDisplay:=ws.NAme 

     i = i + 1 
    Next ws 
End Sub 

回答

1
Sub GetHyperlinks() 
    Dim arrExclude 
    Dim ws As Worksheet 
    Dim i As Integer 

    'Sheets to be excluded from linking 
    arrExclude = Array("Test Results", "some other sheet", "overview") 

    i = 9 

    For Each ws In ThisWorkbook.Worksheets 
     'test to see if not excluded 
     If IsError(Application.Match(ws.Name, arrExclude, 0)) Then 
      ActiveWorkbook.Sheets("overview").Hyperlinks.Add _ 
       Anchor:=ActiveWorkbook.Sheets("overview").Cells(i, 1), _ 
       Address:="", _ 
       SubAddress:="'" & ws.Name & "'!A1", _ 
       TextToDisplay:=ws.Name 
      i = i + 1 
     End If 'include this sheet 
    Next ws 
End Sub