使用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

 

版权声明:本文为514687800原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/514687800/p/5109940.html