1

Hi guys i'm brand new to coding but i have somehow (haha) managed to export my excel into PDF. Now Im having difficulties trying to have the PDF automatically open in PDF XChange Viewer instead of Adobe Reader.

Here are my codes:

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

Disclaimer i copied the codes from somewhere online because i wanted to allow users to name the file, select where they save it.

What should i do to open the PDF in PDFXChange Viewer. The directory is: C:\Program Files\Tracker Software\PDF Viewer

0m3r
  • 12,286
  • 15
  • 35
  • 71
Jay Teo
  • 23
  • 1
  • 6

2 Answers2

1

As you mentioned you already managed to export to PDF, so try below code to open the PDF file in Adobe Reader In case of PDF XChange Viewer put XChange Viewer exe file path in the code.

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

Edit

Sub to save as pdf then open in a program.

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

You have to replace appPath with your XChange viewer path.

Harun24hr
  • 30,391
  • 4
  • 21
  • 36
  • could i ask for your help to see my codes and see how to include what you wrote? sorry i'm a beginner so i don't really understand :( – Jay Teo May 01 '18 at 09:48
  • Can you please provide XChange viewer exe file path like I provided adobe reader path in my code. So, I will provide you full code to save and open the file in xchange viewer. – Harun24hr May 01 '18 at 11:23
  • hi do u mean this: C:\Program Files\Tracker Software\PDF Viewer – Jay Teo May 01 '18 at 11:42
  • It should also have file name like `C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe`. Can you check it? – Harun24hr May 01 '18 at 11:51
  • works now! thanks so much @harun24hr !!! another question: can i add textbox at a specific location in the pdf i have created? – Jay Teo May 02 '18 at 01:47
  • If you found it working then accept (tick it as green) my answer so that other people can know it is useful answer. You can add textbox but I do not know much more about adding textbox. You can ask a separate question for that. – Harun24hr May 02 '18 at 03:15
1

Open PDF in PDFXCview

Below is an example of how to call the application using Shell. You'd need to specify the path/filename of your PDF, and you may need to confirm the location of PDFXCview.exe on your machine.

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 Command Line Options

You can also add command line options if you want to automate more advanced tasks.

For example, you could have it:

  • automatically print and then close the file,
  • hide the user interface,
  • import saved settings,
  • or even run custom JavaScript.

Command Line switches

/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>

More Information Here.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105