【问题标题】:Send txt file to printer with Excel VBA使用 Excel VBA 将 txt 文件发送到打印机
【发布时间】:2015-05-19 17:40:40
【问题描述】:

我有一个创建 .txt 文件的子程序,我想在默认打印机上打印它。如何在 VBA 中实现这一点?

我想我需要调用 ShellExecute API 函数,但我没有找到正确的 sintax。

我将不胜感激!

【问题讨论】:

    标签: vba excel printing text-files


    【解决方案1】:

    我找到了一个可以解决问题的代码:

    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 
    

    【讨论】:

    • 嗨。但是如果我想在不打开文件的情况下打印 pdf 文件?(类似于 openAfterPublish/print:=False)
    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2020-03-19
    相关资源
    最近更新 更多