VBA以PDF格式打开文件导出的Excel文件XChange Viewer

时间:2018-05-01 05:24:47

标签: excel vba excel-vba pdf

大家好,我是编码新手,但我不知怎的(哈哈)设法将我的Excel导出到PDF。现在我很难在 PDF XChange Viewer 而不是Adobe Reader中尝试使用PDF 自动打开

以下是我的代码:

Sub Export()
Dim wsA As Worksheet
Dim wsB As Workbook
Dim strPath As String
Dim myFile As Variant

Set wbA = ActiveWorkbook
Set wsA = ActiveWorksheey

strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"

myFile = Application.GetSaveAsFilename _
(FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")

If myFile <> "False" Then
wsa.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard,_
IncludeDocProperties:=True,_
IgnorePrintAreas:=False,_
OpenAfterPublish:=True

End If
End Sub

免责声明我从网上某处复制了代码,因为我想让用户为文件命名,选择保存文件的位置。

如何在PDFXChange Viewer中打开PDF。目录是:C:\ Program Files \ Tracker Software \ PDF Viewer

2 个答案:

答案 0 :(得分:2)

正如您所提到的,您已设法导出为PDF,因此请尝试以下代码在Adobe Reader中打开PDF文件。如果PDF XChange Viewer在代码中放置了XChange Viewer exe文件路径。

Sub OpenPDFbyAdobeReader()
    Dim exePath, filePath As String
    Dim OpenFile

    exePath = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"
    filePath = "E:\CyberArk\DNA_Datasheet.pdf"
    openPath = exePath & " " & filePath

    OpenFile = Shell(openPath, vbNormalFocus)
End Sub

修改

Sub保存为pdf,然后在程序中打开。

Sub Export()
Dim wsA As Worksheet
Dim wsB As Workbook
Dim strPath As String
Dim myFile As Variant
Dim appPath As String
Dim OpenFile

    Set wbA = ActiveWorkbook
    Set wsA = ActiveWorkbook.ActiveSheet

    appPath = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"

    strPath = wbA.Path
    If strPath = "" Then
        strPath = Application.DefaultFilePath
    End If
        strPath = strPath & "\"

        myFile = Application.GetSaveAsFilename _
        (FileFilter:="PDF Files (*.pdf), *.pdf", _
        Title:="Select Folder and FileName to save")

        If myFile <> "False" Then
            wsA.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=myFile, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False

            OpenFile = Shell(appPath & " " & myFile, vbNormalFocus)
        End If
End Sub

您必须将appPath替换为XChange查看器路径。

答案 1 :(得分:1)

PDFXCview

中打开PDF

以下是如何使用Shell调用应用程序的示例。您需要指定PDF的路径/文件名,并且可能需要确认计算机上PDFXCview.exe的位置。

Sub OpenPDF_test()
    Const XCviewPath = "C:\Program Files\Tracker Software\PDF Editor\PDFXCview.exe"
    Const pdfFileName = "C:\myPath\myPDFfileName.pdf"
    Debug.Print XCviewPath & " """ & pdfFileName & """"
End Sub

PDFXCview.exe命令行选项

如果要自动执行更高级的任务,还可以添加命令行选项。

例如,您可以拥有它:

  • 自动打印然后关闭文件,
  • 隐藏用户界面
  • 导入已保存的设置,
  • 甚至 运行自定义JavaScript

命令行开关

/A "param=value [&param2=value [&...]"
/close[:save|discard|ask]
/print[:[default=yes|no][&showui=yes|no][&printer=<printername>][&pages=<pagesrange>]]
/printto[:[default=yes|no][&showui=yes|no][&pages=<pagesrange>]] <printername>
/exportp <setting_file_name>
/importp <setting_file_name>
/RegServer
/UnregServer
/usep <setting_file_name>

更多信息Here