Advertisement
Guest User

index, create hyperlink

a guest
Jun 30th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Dim ws As Worksheet, Reference As Worksheet, sht As Worksheet
  3. Dim i As Integer, j As Integer, LastRow As Integer, lastcolumn As Integer
  4. Dim m As Integer, n As Integer
  5. Dim ValueDate As Date
  6. Dim sheetname As String
  7. Dim t As String, nsht() As String
  8.  
  9. '显示全部工作表
  10. Sub Show_All()
  11. Application.ScreenUpdating = False
  12.     For i = 1 To Sheets.count
  13.         Sheets(i).Visible = True
  14.     Next i
  15. Call HyperLink
  16. Call ShowColor
  17. Application.ScreenUpdating = True
  18. End Sub
  19.  
  20. 'Index to Tab
  21. Sub Index_Tab()
  22. Application.ScreenUpdating = False
  23. n = Sheets.count
  24. '按照Index表的顺序排序
  25. ReDim nsht(1 To n)
  26. With ThisWorkbook.Worksheets("Index")
  27.     For i = 1 To n
  28.         nsht(i) = .Cells(i + 3, 2).Text
  29.     Next i
  30.     For i = n To 2 Step -1
  31.         Sheets(nsht(i)).Move after:=Sheets("Index")
  32.     Next i
  33. End With
  34. Call ShowColor
  35. Call HyperLink
  36.  
  37. Worksheets("Index").Select
  38. Application.ScreenUpdating = True
  39. End Sub
  40.  
  41. 'Tab to Index
  42. Sub Tab_Index()
  43. Application.ScreenUpdating = False
  44.     n = Sheets.count
  45.    
  46.     With ThisWorkbook.Worksheets("Index")
  47.         .Range(.Cells(n + 3, 1), .Cells(n + 100, 4)).ClearContents
  48.         For i = 5 To n
  49.             .Cells(i, 1) = i - 3
  50.             .Cells(i, 2) = Sheets(i - 3).name
  51.         Next i
  52.     End With
  53. Call ShowColor
  54. Call HyperLink
  55. Worksheets("Index").Select
  56. Application.ScreenUpdating = True
  57. End Sub
  58.    
  59.  
  60. '显示选定的工作表
  61. Sub Show_Select()
  62. Application.ScreenUpdating = False
  63. With ThisWorkbook.Worksheets("Index")
  64.     LastRow = .Cells(4, 1).End(xlDown).Row
  65.     For i = 5 To LastRow
  66.         sheetname = .Cells(i, 2)
  67.         Select Case .Cells(i, 3)
  68.             Case 1
  69.                 ThisWorkbook.Worksheets(sheetname).Visible = True
  70.             Case Else
  71.                 ThisWorkbook.Worksheets(sheetname).Visible = False
  72.         End Select
  73.     Next i
  74. End With
  75. sheetname = ""
  76. Application.ScreenUpdating = True
  77. End Sub
  78.  
  79.  
  80. '删除选定的工作表
  81. Sub Delete_Select()
  82. Application.ScreenUpdating = False
  83. Application.DisplayAlerts = False
  84. With ThisWorkbook.Worksheets("Index")
  85.     LastRow = .Cells(4, 1).End(xlDown).Row
  86.     For i = 5 To LastRow
  87.         sheetname = .Cells(i, 2)
  88.         If .Cells(i, 3) = 1 Then
  89.             On Error Resume Next
  90.             ThisWorkbook.Worksheets(sheetname).Delete
  91.         End If
  92.     Next i
  93. End With
  94. sheetname = ""
  95. Application.DisplayAlerts = True
  96. Application.ScreenUpdating = True
  97. End Sub
  98.  
  99. Sub ShowColor()
  100. '确定行是否标色
  101. With Worksheets("Index")
  102. For i = 4 To .Cells(3, 1).End(xlDown).Row + 10
  103.     On Error Resume Next
  104.     If InStr(.Cells(i, 2), "--") > 0 Then
  105.         .Range(.Cells(i, 1), .Cells(i, 4)).Interior.Color = 10092543
  106.         .Range(.Cells(i, 1), .Cells(i, 4)).Font.ThemeColor = xlThemeColorLight1
  107.     Else
  108.         .Range(.Cells(i, 1), .Cells(i, 4)).Interior.Pattern = xlNone
  109.     End If
  110. Next i
  111. End With
  112. End Sub
  113.  
  114. Sub HyperLink()
  115. '在Index表建立hyperlink
  116. With ThisWorkbook.Worksheets("Index")
  117. n = Sheets.count
  118.     For i = 5 To n + 3
  119.         .Cells(i, 1) = i - 3
  120.         .Cells(i, 2) = Sheets(i - 3).name '原来采用在Excel中定义一个名称的方式 AllSheetsName=REPLACE(GET.WORKBOOK(1),1,FIND("]",GET.WORKBOOK(1)),)&T(NOW())
  121.        .Hyperlinks.Add Anchor:=.Cells(i, 2), Address:="", SubAddress:="'" & .Cells(i, 2).Text & "'" & "!A1", TextToDisplay:=Application.WorksheetFunction.Trim(.Cells(i, 2))
  122.         .Cells(i, 2).Font.Underline = xlUnderlineStyleNone
  123.     Next i
  124. End With
  125.  
  126. '在其他表建立Hyperlink
  127. For Each ws In Worksheets
  128.     If ws.CodeName <> "Index" Then
  129.         If ws.Range("A1") = "" Then
  130.             ws.Range("A1") = "Index"
  131.         End If
  132.         ws.Range("A1").Hyperlinks.Add Anchor:=ws.Range("A1"), Address:="", SubAddress:="Index!A1", TextToDisplay:=Application.WorksheetFunction.Trim(ws.Range("A1").Text)
  133.     End If
  134. Next
  135. End Sub
  136.  
  137.  
  138. 'Delete unneed styles
  139. Sub DelCustomStyles()
  140. Dim st As Style
  141. For Each st In ActiveWorkbook.Styles
  142.     On Error Resume Next
  143.     If Not st.BuiltIn Then st.Delete
  144. Next
  145. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement