在下面的代码中,我们可以将Sheet1-Sheet4置于选择模式并进行复制。但这里的重点是张数不同。每次更改文件时,图纸数量都会变少或变多。我只想复制第1张。。。。n,并非所有图纸。(带有"工作表">名称的每张工作表。如何针对此问题更正此代码?
Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Copy
Sub m()
Dim nSht As Long
ReDim shts(1 To Worksheets.Count) As String
Dim sht As Worksheet
For Each sht In Worksheets
If sht.Name Like "Sheet*" Then
nSht = nSht + 1
shts(nSht) = sht.Name
End If
Next
If nSht > 0 Then
ReDim Preserve shts(1 To nSht)
Worksheets(shts).Copy
End If
仅供记录,这是破坏的第一个解决方案
Dim sht As Worksheet
For Each sht In Worksheets
If sht.Name Like "Sheet*" Then
If Not ActiveSheet.Name Like "Sheet*" Then sht.Activate
sht.Select False
End If
Next
ThisWorkbook.Windows(1).SelectedSheets.Copy