批量横向打印Excel

时间:2024-03-02 11:33:14

使用VBA脚本写的,具体使用如下:在批量需要打印的Excel文档下面,新建一个文档,将代码粘贴VBA工程里,然后运行即可。

具体代码如下:

Attribute VB_Name = "模块1"
Sub PiLiangPring()
Attribute PiLiangPring.VB_ProcData.VB_Invoke_Func = " \n14"
Dim curPath As String
curPath = ThisWorkbook.Path & "\"
Dim xlsFile As String
xlsFile = Dir(curPath & "*.xls")
While xlsFile <> ""
    If xlsFile <> ThisWorkbook.Name Then
       Excel.Application.Workbooks.Open (curPath & xlsFile)
       \'激活最新的工作簿
       Excel.Application.Workbooks(Excel.Application.Workbooks.Count).Activate
       \'设置纸张类型为A4
       Excel.Application.Workbooks(Excel.Application.Workbooks.Count).ActiveSheet.PageSetup.PaperSize = 9
       \'打印方向设置为横向
       Excel.Application.Workbooks(Excel.Application.Workbooks.Count).ActiveSheet.PageSetup.Orientation = 2
       \'仅打印激活的工作表
       Excel.Application.Workbooks(Excel.Application.Workbooks.Count).ActiveSheet.PrintOut
       Excel.Application.Workbooks(xlsFile).Close (False)
    End If
    xlsFile = Dir
Wend
MsgBox ("Print Done")
End Sub