我继承了一个 Access 程序,该程序运行良好至少 10 年。
它执行的任务之一 - 以整理的方式打印一批 10 到 100 份报告和关联的 PDF 文档。
如果关联文档是 Word 或 Excel - 一切顺利。
打印PDF时,打印了报告但没有PDF。没有错误,没有打印输出。就像进入黑洞一样消失了。
我需要隐藏 Acrobat,或者至少最小化。
此代码将打开 Acrobat。如果我单击“打印”图标,它会正常打印。
lngRetVal = ShellExecute&(lngHwnd,“打开”,strPath,vbNullString,vbNullString,SW_SHOWNORMAL)
不是一个选择!
如果我尝试调用“打印”而不是“打开” - 没有 Acrobat 打开,队列中没有打印作业,没有打印文档,没有错误。
lngRetVal = ShellExecute&(lngHwnd,“打印”,strPath,vbNullString,vbNullString,SW_HIDE)
所以现在它的范围缩小到“打印”,不执行任何操作,不向打印机发送命令。
不仅如此,如果我使用“打印”和 SW_SHOWNORMAL Acrobat 也不会打开并给我一条消息“Acrobat 意外退出......”。
我(以及运行此 Access 应用程序的所有其他计算机)参考文献中有 Acrobat Library 10。
Office 365。
代码已于2013年采用64位系统。
问题从 9 月 14 日开始。
有人提出可能与Win更新有关。
我进行了回滚 - 没有变化。
没关系,如果:
打印机是网络或本地
访问应用程序正在哪台计算机上运行
我已尝试在 Microsoft 社区支持中寻求帮助,但仍然没有任何进展。
请帮忙。
这是一个示例代码,将循环遍历该文件夹中的所有 PDF 文件并打印它们。
#If VBA7 Then
Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
#Else
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
Sub PrintPDFFiles()
Dim FolderPath As String, FileName As String, PDFPath As String
Dim hWnd As LongPtr, Result As LongPtr
'Your PDF files are located
FolderPath = ThisWorkbook.Path & "\"
hWnd = Application.hWnd
' Loop All files in the folder
FileName = Dir(FolderPath & "*" & ".pdf")
Do While FileName <> ""
PDFPath = FolderPath & FileName
Result = ShellExecute(hWnd, "Print", PDFPath, vbNullString, vbNullString, 3)
If Result <= 32 Then
MsgBox "Failed to print " & PDFPath
Else
' Adjust the duration as needed
Application.Wait Now + TimeValue("00:00:05")
Call Shell("taskkill /f /im AcroRd32.exe", vbHide)
End If
FileName = Dir
Loop
End Sub