Excel Skill---Generate Table of Contents based on Sheet Name (根据Sheet名称产生目录)
2015-03-16 16:59
465 查看
Sub mulu()
On Error GoTo Tuichu
Dim i As Integer
Dim ShtCount As Integer
Dim SelectionCell As Range
ShtCount = Worksheets.Count
If ShtCount = 0 Or ShtCount = 1 Then Exit Sub
Application.ScreenUpdating = False
For i = 1 To ShtCount
If Sheets(i).Name = "Inventory" Then
Sheets("Inventory").Move Before:=Sheets(1)
End If
Next i
If Sheets(1).Name <> "Inventory" Then
ShtCount = ShtCount + 1
Sheets(1).Select
Sheets.Add
Sheets(1).Name = "Inventory"
End If
Sheets("Inventory").Select
Columns("B:B").Delete Shift:=xlToLeft
Application.StatusBar = "Generating Inventory…………WAITING!"
For i = 2 To ShtCount
ActiveSheet.Hyperlinks.Add Anchor:=Worksheets("Inventory").Cells(i, 2), Address:="", SubAddress:= _
"'" & Sheets(i).Name & "'!R1C1", TextToDisplay:=Sheets(i).Name
Next
Sheets("Inventory").Select
Columns("B:B").AutoFit
Cells(1, 2) = "Inventory"
Set SelectionCell = Worksheets("Inventory").Range("B1")
With SelectionCell
.HorizontalAlignment = xlDistributed
.VerticalAlignment = xlCenter
.AddIndent = True
.Font.Bold = True
.Interior.ColorIndex = 34
End With
Application.StatusBar = False
Application.ScreenUpdating = True
Tuichu:
End Sub
On Error GoTo Tuichu
Dim i As Integer
Dim ShtCount As Integer
Dim SelectionCell As Range
ShtCount = Worksheets.Count
If ShtCount = 0 Or ShtCount = 1 Then Exit Sub
Application.ScreenUpdating = False
For i = 1 To ShtCount
If Sheets(i).Name = "Inventory" Then
Sheets("Inventory").Move Before:=Sheets(1)
End If
Next i
If Sheets(1).Name <> "Inventory" Then
ShtCount = ShtCount + 1
Sheets(1).Select
Sheets.Add
Sheets(1).Name = "Inventory"
End If
Sheets("Inventory").Select
Columns("B:B").Delete Shift:=xlToLeft
Application.StatusBar = "Generating Inventory…………WAITING!"
For i = 2 To ShtCount
ActiveSheet.Hyperlinks.Add Anchor:=Worksheets("Inventory").Cells(i, 2), Address:="", SubAddress:= _
"'" & Sheets(i).Name & "'!R1C1", TextToDisplay:=Sheets(i).Name
Next
Sheets("Inventory").Select
Columns("B:B").AutoFit
Cells(1, 2) = "Inventory"
Set SelectionCell = Worksheets("Inventory").Range("B1")
With SelectionCell
.HorizontalAlignment = xlDistributed
.VerticalAlignment = xlCenter
.AddIndent = True
.Font.Bold = True
.Interior.ColorIndex = 34
End With
Application.StatusBar = False
Application.ScreenUpdating = True
Tuichu:
End Sub
相关文章推荐
- How can I dump only certain entries of a table based on my condition?
- Refreshing One Column based on the value of Another Column in ADFdi Table
- SQL Server ->> Move characters in string N position(s) forward/backward based on ASCII table(根据ASCII表的排列顺序将字符串内的数值往前或者后移N个位)
- Sharepoint site showing system account instead of my username on the top right corner.
- The Design and Implementation of Two-dimensional Vector Graphics Interactive Tools Based on “Smart Handle”
- (转贴)仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'TableName' 中为标识列指定显式值。
- Can't perform Create, Update or Delete operations on 'Table(@TableName)' because it is read-only.
- using INSTR function for obtaining data from a table, based on a selection from the master table (FK relation)
- GuestStealer allows for the stealing of VMware guests from vulnerable hosts based on the Directory Traversal Vulnerability
- New version of wxDesigner based on wxWidgets pre-3.0 released
- Get XML tree format based on the tree data in SQL server table
- Research on Computer Aided Design Method for the particles distribution of Table-tennis racket
- Generate Insert data script on a table.
- Is Criticism of Obama Based on His Race?
- Course Map/Table of Contents
- [论文笔记] A service creation environment based on end to end composition of Web services (WWW, 2005)
- The promise of MOM based on XMPP
- Paper Research on the scheme of spatial database building based on the integration of GIS and CAD finished
- 复制表,仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'TableName' 中为标识列指定显式值。
- Video Synchronization Based on Co-occurrence of Appearance Changes