大家好,我是编码新手,但我不知何故(哈哈)设法将我的 excel 导出到 PDF
.现在我在尝试拥有 PDF 时遇到了困难自动开启在 PDF XChange 查看器 而不是 Adobe Reader。
这是我的代码:
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
最佳答案
正如您提到的,您已经成功导出为 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 查看器路径。
关于VBA 在 PDF XChange Viewer 中打开文件导出的 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50111696/