vba Excel - 创建打印宏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3215804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:51:52  来源:igfitidea点击:

Excel - Creating a print macro

excelexcel-vbavba

提问by BioXhazard

I recorded a macro to print an excel sheet when the button is pressed. But I want to specify the printer that it automatically prints to rather than give the user a choice. I'm also printing to a PDF so is there a way I can choose where I print to?

当按下按钮时,我录制了一个宏来打印 Excel 工作表。但我想指定它自动打印到的打印机,而不是让用户选择。我也打印到 PDF,所以有什么方法可以选择打印到的位置吗?

This is what I have so far:

这是我到目前为止:

Sub Publish()
    '
    ' Publish Macro
    ' Macro recorded 07/09/2010
    '
    ' Keyboard Shortcut: Ctrl+Shift+S
    '
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
    End Sub

采纳答案by JohnK813

Try adding

尝试添加

Application.ActivePrinter = "Printer Name"

Application.ActivePrinter = "Printer Name"

on the line above the PrintOut command. This linkgives more information on ActivePrinter, even though it is geared more for MS Word.

在 PrintOut 命令上方的行上。 此链接提供了有关 ActivePrinter 的更多信息,尽管它更适合 MS Word。