我在MS Word中使用宏打印出文档(到虚拟pdf打印机),保存文件并关闭文档:
Sub PrintClose()
ActiveDocument.PrintOut Copies:=1
ActiveDocument.Save
If Application.Documents.Count > 1 Then
ActiveDocument.Close
Else
Application.Quit
End If
End Sub问题是打印的文档有时是不可读的。可以打开,但是字符都是错的。
我认为问题可能是文档在正确执行打印之前关闭得太快,因为当我在我的虚拟pdf打印机(PDF24)中打开打印的文档时,它已经是可读的。因此,我认为问题不在于pdf打印机,而在于打印过程。因此,我试图在打印和关闭之间添加延迟。
我只能像这样使用Excels的等待命令:
CreateObject("Excel.Application").Wait (Now + TimeValue("00:00:05"))
但是这个命令总是首先执行,不管我把它放在哪里。所以Word等待指定的时间,然后打印,然后关闭,这并不能解决我的问题。
是否可以在MS Word中增加打印和关闭文档之间的延迟?我在Visual Basic或一般编程方面不是很熟练。
发布于 2020-04-30 04:30:05
您有没有尝试添加DoEvents?docs
Sub PrintClose()
ActiveDocument.PrintOut Copies:=1
DoEvents
ActiveDocument.Save
If Application.Documents.Count > 1 Then
ActiveDocument.Close
Else
Application.Quit
End If
End Sub或者,尝试@Cindy Meister建议:
Sub PrintClose()
Application.Options.PrintBackground:=False
ActiveDocument.PrintOut Copies:=1
ActiveDocument.Save
If Application.Documents.Count > 1 Then
ActiveDocument.Close
Else
Application.Quit
End If
End Sub或者第三个选项:docs
Sub PrintClose()
ActiveDocument.PrintOut Copies:=1
Do While Application.BackgroundPrintingStatus > 0
DoEvents
Loop
ActiveDocument.Save
If Application.Documents.Count > 1 Then
ActiveDocument.Close
Else
Application.Quit
End If
End SubPS:这里有三个选择,因为我不能复制你的问题,因此也不能自己测试它…
https://stackoverflow.com/questions/61500049
复制相似问题