我有一个自动打印多个文件的代码,但此代码会打印文件中的每一张纸
现在我有 44 个文件,每个文件有 3 张表 [Sheet1,Sheet2,Sheet3] 我只想打印 Sheet1
Sub auto_print()
'
'
Dim i As Integer, j As Integer
Dim varFile As Variant
Dim inFile As Integer
Dim OPENFILE
Dim currFile
Dim N
'
Application.ScreenUpdating = False
On Error GoTo 100
'
currFile = ActiveWorkbook.Name
varFile = _
Application.GetOpenFilename(FileFilter:="Microsoft Excel file, *.xls", MultiSelect:=True)
If (IsArray(varFile)) Then
For intfile = 1 To UBound(varFile)
Workbooks.OpenText Filename:=varFile(intfile)
OPENFILE = ActiveWorkbook.Name
'
For N = 1 To ActiveWorkbook.Sheets.Count
Sheets(N).Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next N
Workbooks(OPENFILE).Close
Next intfile
Else
MsgBox "You did not select any file.", vbOKOnly + vbInformation
End If
100 End Sub
答案1
改变
For N = 1 To ActiveWorkbook.Sheets.Count
Sheets(N).Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next N
到
Sheets("Sheet1").PrintOut Copies:=1, Collate:=True