使用带有预定义路径和文件名的 Adob​​e PDF PrintOut [英] Using PrintOut for Adobe PDF with predefined path and file name

查看:71
本文介绍了使用带有预定义路径和文件名的 Adob​​e PDF PrintOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印一个启用宏的 MS-Word 文档,该文档嵌入在 Excel 工作表中,它的名称是 SalaryPaycheck,来自 excel 宏模块.

I want to print a macro-enabled MS-Word Document that is embedded in a Excel Worksheet which it's name is SalaryPaycheck, from the excel macro module.

我使用下面的代码:

Sub PrintIt()

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim Oshp As Object
    Dim strCurrentPrinter As String

    ActiveSheet.OLEObjects("SalaryPaycheck").Activate
    Set objWord = GetObject(, "Word.Application")
    objWord.Visible = False
    Set objDoc = objWord.ActiveDocument
    objWord.Application.DisplayAlerts = wdAlertsNone
    objDoc.Application.ActivePrinter = "Adobe PDF on Ne06:"


    objDoc.PrintOut Background:=False


    objWord.Quit
    Set objDoc = Nothing
    Set objWord = Nothing
    Application.ScreenUpdating = True
    Exit Sub

End Sub 'Print it

PrintOut 打开一个对话框,询问路径和文件名.

The PrintOut opens a dialog box which asks about path and file name.

我想预定义文件名和路径,以便 PrintOut 安静地运行.

I want to made file name and path predefined so PrintOut runs quietly.

推荐答案

如果您有最新的 Word 版本,那么您可以直接将文件导出/保存为 PDF 文档.将您的代码更改为

If you have an up-to-date Word version then you could export/save the file to a PDF document directly. Change your code to

Sub PrintIt()

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim Oshp As Object
    Dim strCurrentPrinter As String

    ActiveSheet.OLEObjects("SalaryPaycheck").Activate
    Set objWord = GetObject(, "Word.Application")
    objWord.Visible = False
    Set objDoc = objWord.ActiveDocument
    objWord.Application.DisplayAlerts = wdAlertsNone
 '   objDoc.Application.ActivePrinter = "Adobe PDF on Ne06:"
 '   objDoc.PrintOut Background:=False

    Dim strOutFile As String
    strOutFile = "<filename>.pdf"

    objDoc.ExportAsFixedFormat OutputFileName:= _
        strOutFile, ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
        wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent



    objWord.Quit
    Set objDoc = Nothing
    Set objWord = Nothing
    Application.ScreenUpdating = True
    Exit Sub

End Sub

这篇关于使用带有预定义路径和文件名的 Adob​​e PDF PrintOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆