【发布时间】:2015-05-19 17:40:40
【问题描述】:
我有一个创建 .txt 文件的子程序,我想在默认打印机上打印它。如何在 VBA 中实现这一点?
我想我需要调用 ShellExecute API 函数,但我没有找到正确的 sintax。
我将不胜感激!
【问题讨论】:
标签: vba excel printing text-files
我有一个创建 .txt 文件的子程序,我想在默认打印机上打印它。如何在 VBA 中实现这一点?
我想我需要调用 ShellExecute API 函数,但我没有找到正确的 sintax。
我将不胜感激!
【问题讨论】:
标签: vba excel printing text-files
我找到了一个可以解决问题的代码:
Option Explicit
Declare Function apiShellExecute 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
Public Sub PrintFile(ByVal strPathAndFilename As String)
Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0)
End Sub
Sub Test()
PrintFile ("C:\Test.pdf")
End Sub
【讨论】: