怎么快速提取一个excel文件中的所有工作表名
2个回答
展开全部
这个只能用vba来解决:
取所有工作表名称
按下 alt+f11 ,选择插入 模块,然后复制如下代码:
Sub Excel各页名()
Dim XStr, YStr, ZStr
XStr = " -"
ZStr = ""
For i = 1 To Worksheets.Count
If Worksheets(i).Name =
"目录" Then
Exit For
End If
Next
If i > Worksheets.Count
Then
Sheets.Add
ActiveSheet.Name =
"目录"
End If
Sheets("目录").Move
before:=Sheets(1)
Sheets("目录").Select
Range("A:B").Clear
Range("B:B").NumberFormatLocal
= "@"
Worksheets(1).Cells(1,
1).Value = "序号"
Worksheets(1).Cells(1,
2).Value = "名称"
For i = 2 To Worksheets.Count
Worksheets(1).Cells(i,
1).Value = i - 1
Worksheets(1).Cells(i,
2).Value = Worksheets(i).Name
For j = 1 To
Len(Worksheets(i).Name)
YStr = Mid(Worksheets(i).Name,
j, 1)
If InStr(XStr, YStr) <>
0 Then
ZStr = "'"
Exit For
End If
Next
ActiveSheet.Hyperlinks.Add
Anchor:=Worksheets(1).Cells(i, 2), Address:="", SubAddress:=ZStr
& Worksheets(i).Name & ZStr & "!A1",
TextToDisplay:=Worksheets(i).Name
Next
Range("A:A").HorizontalAlignment
= xlCenter
Rows("1:1").HorizontalAlignment
= xlCenter
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select
End Sub
然后运行宏(可能会提示无法使用vba需要另外保存支持格式之类)
取所有工作表名称
按下 alt+f11 ,选择插入 模块,然后复制如下代码:
Sub Excel各页名()
Dim XStr, YStr, ZStr
XStr = " -"
ZStr = ""
For i = 1 To Worksheets.Count
If Worksheets(i).Name =
"目录" Then
Exit For
End If
Next
If i > Worksheets.Count
Then
Sheets.Add
ActiveSheet.Name =
"目录"
End If
Sheets("目录").Move
before:=Sheets(1)
Sheets("目录").Select
Range("A:B").Clear
Range("B:B").NumberFormatLocal
= "@"
Worksheets(1).Cells(1,
1).Value = "序号"
Worksheets(1).Cells(1,
2).Value = "名称"
For i = 2 To Worksheets.Count
Worksheets(1).Cells(i,
1).Value = i - 1
Worksheets(1).Cells(i,
2).Value = Worksheets(i).Name
For j = 1 To
Len(Worksheets(i).Name)
YStr = Mid(Worksheets(i).Name,
j, 1)
If InStr(XStr, YStr) <>
0 Then
ZStr = "'"
Exit For
End If
Next
ActiveSheet.Hyperlinks.Add
Anchor:=Worksheets(1).Cells(i, 2), Address:="", SubAddress:=ZStr
& Worksheets(i).Name & ZStr & "!A1",
TextToDisplay:=Worksheets(i).Name
Next
Range("A:A").HorizontalAlignment
= xlCenter
Rows("1:1").HorizontalAlignment
= xlCenter
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select
End Sub
然后运行宏(可能会提示无法使用vba需要另外保存支持格式之类)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |