大家好,我是编码新手,但我不知怎的(哈哈)设法将我的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
答案 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
以下是如何使用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
命令行选项如果要自动执行更高级的任务,还可以添加命令行选项。
例如,您可以拥有它:
命令行开关
/A "param=value [¶m2=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>