[英]Send txt file to printer with Excel VBA
I have a sub that creates a .txt file and I want to print it in the default printer. 我有一个创建.txt文件的子程序,我想在默认打印机中打印它。 How can I achieve this in VBA? 如何在VBA中实现这一目标?
I think I need to call the ShellExecute API Function, but I did not find the correct sintax for that. 我想我需要调用ShellExecute API函数,但是我没有找到正确的正弦函数。
I would appreciate any help! 我将不胜感激任何帮助!
I cannot comment yet, so most will ask you to show the code that you tried and then you get help here. 我目前无法发表评论,因此大多数人会要求您显示您尝试过的代码,然后在此处获得帮助。 I did a quick google search and found many examples. 我做了一个快速的谷歌搜索,发现了很多例子。 Search this and I found some code snippets 搜索这个,我发现了一些代码片段
excel vba print file
I found a code that do the trick: 我找到了可以解决问题的代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.