0

here are my codes:

Sub Export()
Dim wsA As Worksheet
Dim wsB As Workbook
Dim strPath As String
Dim strName As String
Dim strPathFile As String
Dim OpenFile

Set wbA = ActiveWorkbook
Set wsA = ActiveWorksheet

strPath = CreateObject("WScript.Shell").specialfolders("Desktop")
If strPath = "" Then
strPath = wbA.path
End If
strPath = strPath & "\"

strName = "My Document"

strFile = strName & ".pdf"
strPathFile = strPath & strFile

wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard,_
IncludeDocProperties:=True,_
IgnorePrintAreas:=False,_
OpenAfterPublish:=False

appPath = "C:\Program Files\TrackerSoftware\PDFViewer\PDFXCView.exe"
OpenFile = Shell(appPath&" "& strPathFile, vbNormalFocus)
End Sub

My generated PDF could be opened on xchange viewer if i didn't command it to save in desktop. Now it only opens Xchange Viewer without my document :(

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Jay Teo
  • 23
  • 1
  • 6
  • if your path in `strPathFile` contains spaces you will probably need to wrap it in quotes `""`. So try `Shell("""" & appPath & """ """ & strPathFile & """", vbNormalFocus)` – Pᴇʜ May 08 '18 at 06:29
  • copied your codes but it didn't seem to work. if my strPathFile does not have spaces, there wouldn't be a problem? – Jay Teo May 08 '18 at 11:25
  • Well, test it. This was just my assumption because usually you need to put a path with spaces into quotes. So usually your command should look something like `"C:\Program Files\TrackerSoftware\PDFViewer\PDFXCView.exe" "C:\My Space Path\file.pdf"` and that should work – Pᴇʜ May 08 '18 at 11:31
  • hmm what is the purpose of the " ? also, between appPath and strPathFile, there is 2x 3" and a space? – Jay Teo May 08 '18 at 14:52
  • Space is a separator between `PDFXCView.exe` and the pdf file. So any space in the path of the file would be considered as another separator which breaks the path! Wrapping the path into quotes ensures that the space in the path is NOT considered as separator and the path keeps together. • In VBA quotes within a string need to be doubled (see https://stackoverflow.com/questions/42960548/placing-double-quotes-within-a-string-in-vba) – Pᴇʜ May 08 '18 at 15:11
  • tried and it worked thanks buddy – Jay Teo May 09 '18 at 03:39

0 Answers0