|
批量打印当前文件夹的EXCEL文件本来是在2007版本用的,现在升级到2016版本就不可以使用了,运行程序打印机无反应!求大神看看2007和2016哪里不一样了,
Option Explicit
Sub 打印指定文件()
Dim A, X, Y, Z As Integer
A = Range("F1")
X = Range("F2")
Y = Range("F3")
Z = Range("F4")
Dim iPath$, iName$, Wb As Workbook
iPath = ThisWorkbook.Path & "\"
iName = Dir(iPath & "*.xl**")
On Error Resume Next
Do While iName <> ""
Set Wb = Workbooks.Open(iPath & iName)
If iName <> ThisWorkbook.Name Then
'这里可以添加修改
ActiveWorkbook.Save
'指定待打印的工作表
Select Case A
Case Is = 1
Wb.Sheets(1).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = 2
Wb.Sheets(2).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = 3
Wb.Sheets(3).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = "1~2"
Wb.Sheets(1).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(2).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = "2~7" '记录页数
Wb.Sheets(2).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(3).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(4).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(5).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(6).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(7).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = "2~5" '记录页数
Wb.Sheets(2).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(3).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(4).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(5).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
Case Is = "3~4" '记录页数
Wb.Sheets(3).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Sheets(4).PrintOut From:=X, To:=Y, Copies:=Z '打印Z份,打印X-Y页
Wb.Close
End Select
End If
iName = Dir
|
|