1、首先,我分享第一个方法,这个方法可是非常简单的哦。打开一个含有多个工作表的excel工作薄,然后新建一个工作表,此处命名为“汇总表”。
2、找到“查看代码”并打开,查找方法如下图所示,有以下两个方法:1鼠标右键点击“汇总表”,在下拉菜单中找到“查看代码”;2找到工具栏中的“开发工具”,可以看到“查看代码”在“控件”下拉菜单中。
3、点击“查看代码”后进入如下对话框,双击“sheet7(汇总表)”可以看到右边d出sheet7代码输入框,在其中输入以下内容:
Sub a()
For Each sh In Sheets
k = k + 1
Cells(k, 1) = shName
Next
End Sub
答:
Sub Demo()Dim Wkb As Workbook
Dim Sht As Worksheet
Dim Drng As Range
Set Drng = Sheets("sheet999")Range("A1")
Set Wkb = GetObject("F:\1xlsx")
For Each Sht In WkbSheets
Drng = ShtName
Set Drng = DrngOffset(1, 0)
Next
With Wkb
Windows(Name)Visible = True
Close SaveChanges:=False
End With
End Sub
在当前工作表的A列生成结果:
Sub test()Dim ar(1 To 100, 1 To 1)
Dim i As Long, j As Long
For i = 1 To SheetsCount
If Sheets(i)Visible = xlSheetVisible Then
j = j + 1
ar(j, 1) = Sheets(i)Name
End If
Next i
With ActiveSheetCells(1, 1)
Resize(RowsCount)ClearContents
Resize(j) = ar
End With
End Sub
hx95华夏联盟
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)