EXCEl怎么用VBA建立一个目录(用超链接)
发布网友
发布时间:2022-04-22 06:36
我来回答
共1个回答
热心网友
时间:2023-10-05 15:36
VBA,在要制作目录工作表中添加如下代码:
Option Explicit
Private Sub Worksheet_Activate()
Dim sh As Worksheet
Dim a As Integer
Dim R As Integer
R = Sheet1.[A65536].End(xlUp).Row
a = 2
If Sheet1.Cells(2, 1) <> "" Then
Sheet1.Range("A2:A" & R).ClearContents
End If
For Each sh In Worksheets
If sh.CodeName <> "Sheet1" Then
Sheet1.Cells(a, 1).Value = sh.Name
a = a + 1
End If
Next
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim R As Integer
R = Sheet1.[A65500].End(xlUp).Row
On Error Resume Next
If Target.Count = 1 Then
If Target.Column = 1 Then
If Target.Row > 1 And Target.Row <= R Then
Sheets(Target.Value).Select
End If
End If
End If
End Sub