none
Save word document as pdf using VBA

    Question

  • Hi there
    I am working on a Excel (2010) using VBA where I am creating a MS word document and I want to save the document as  pdf is it possible?
    If so how can I do it
    Thanks for your help and assistance
    Thursday, April 19, 2012 2:53 PM

Answers

  • Are you using Automation to control Word from Excel? If so, I assume that you have a variable of type Word.Document (or Object if you use late binding) that refers to the document that you create. Let's say you have named this variable objDoc.

    You can save the document as PDF as follows:

        objDoc.SaveAs2 "C:\Docs\MyDoc.pdf", 17

    17 is the value of the symbolic constant wdFormatPDF.

    If you haven't created a variable for the document, but refer to the active document in the Word application object, say objWordApp:

        objWordApp.ActiveDocument.SaveAs2 "C:\Docs\MyDoc.pdf", 17


    Regards, Hans Vogelaar

    • Marked as answer by Rushdy Najath Thursday, April 19, 2012 3:13 PM
    Thursday, April 19, 2012 3:02 PM

All replies

  • Are you using Automation to control Word from Excel? If so, I assume that you have a variable of type Word.Document (or Object if you use late binding) that refers to the document that you create. Let's say you have named this variable objDoc.

    You can save the document as PDF as follows:

        objDoc.SaveAs2 "C:\Docs\MyDoc.pdf", 17

    17 is the value of the symbolic constant wdFormatPDF.

    If you haven't created a variable for the document, but refer to the active document in the Word application object, say objWordApp:

        objWordApp.ActiveDocument.SaveAs2 "C:\Docs\MyDoc.pdf", 17


    Regards, Hans Vogelaar

    • Marked as answer by Rushdy Najath Thursday, April 19, 2012 3:13 PM
    Thursday, April 19, 2012 3:02 PM
  • thanks a lot it works

    Thursday, April 19, 2012 3:13 PM