-1

I need to get the file location of the PDF after converting from a docx

I got the code below which converts but it doesn't give any info on the PDF location

mydoc.ExportAsFixedFormat _
Outputfilename:=Replace(mydoc.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, 
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, Item:=wdExportDocumentContent

I am hoping that after it converts, i can log the PDF location to a cell.

Thanks

braX
  • 11,506
  • 5
  • 20
  • 33
Robert Hall
  • 191
  • 3
  • 11
  • You already have `mydoc.FullName`. You can easly get the file path from it... See @Makah answer [HERE](https://stackoverflow.com/questions/418622/find-the-directory-part-minus-the-filename-of-a-full-path-in-access-97) – Siddharth Rout Oct 22 '19 at 10:47
  • `Left(mydoc.FullName, InStrRev(mydoc.FullName, "\"))` – Siddharth Rout Oct 22 '19 at 10:50

1 Answers1

1

myDoc.FullName includes the path to the file, so when you set this as the export's output filename and just replace the extension from .docx to .pdf, then you have set the path for the PDF to be the same folder as the original document.

Use the value from here to set your cell with the filepath to the PDF.

ThisWorkbook.Worksheets("sheetname").Range("A1").Value = Replace(myDoc.FullName, ".docx", ".pdf")

This will set cell A1 on worksheet "sheetname" to the file path of the pdf.

Dave
  • 4,328
  • 2
  • 24
  • 33