打印Word时,弹出警告框,提示:页边距非常小。打印时,您的部分内容可能会被截断。是否仍要打印?的问题,可以用如下方案解决。
' 打印文档并自动处理警告框
Application.DisplayAlerts = wdAlertsNone
On Error Resume Next
wdDoc.PrintOut Background:=False
If Err Then
Application.DisplayAlerts = wdAlertsAll
On Error GoTo 0
MsgBox "打印出错。"
Else
Application.DisplayAlerts = wdAlertsAll
On Error GoTo 0
End If
完整代码如下:
Function printALL(strFolderPath As String)
' 初始化Word应用程序
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = False
' 打印指定文件夹下的所有Word文档
strFileType = "*.doc*"
strFileName = Dir(strFolderPath & strFileType)
Do While strFileName <> ""
strFilePath = strFolderPath & strFileName
' 打开Word文档
Set wdDoc = wdApp.Documents.Open(strFilePath)
' 打印文档并自动处理警告框
Application.DisplayAlerts = wdAlertsNone
On Error Resume Next
wdDoc.PrintOut Background:=False
If Err Then
Application.DisplayAlerts = wdAlertsAll
On Error GoTo 0
MsgBox "打印出错。"
Else
Application.DisplayAlerts = wdAlertsAll
On Error GoTo 0
End If
' 关闭Word文档和应用程序
wdDoc.Close False
' 指向下一个文件
strFileName = Dir
Loop
' 关闭Word应用程序
wdApp.Quit
' 释放对象
Set wdDoc = Nothing
Set wdApp = Nothing
End Function