+ Reply to Thread
Results 1 to 10 of 10

Code to save a word doc to pdf

  1. #1
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Code to save a word doc to pdf

    Hi guys,

    I have this macro and i want to save the report as pdf not as doc or docx.
    How can i customize my macro in order to save the file as pdf?

    Please Login or Register  to view this content.

    Thank you in advance,
    Ionut

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Code to save a word doc to pdf

    This is how VBA expects the information
    Please Login or Register  to view this content.
    Tailor your code as follows
    Amend
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    amend
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    You do not need to distinguish between doc and docx and so you can remove both IF conditions
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Code to save a word doc to pdf

    Hi Kevin,

    Is working properly. Thank you for your help. I had to change the wdExportFormatPDF to 17.

    The line .ActiveDocument.Close is making problems now. I receive an open dialog box in order to save the doc when that line is executed and if i close the dialog box it seems that I have the error run tim error 4198.

    If you can help, I would owe you.

    Thanks,
    Ionut
    Last edited by IonutC; 04-20-2016 at 02:58 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Code to save a word doc to pdf

    I suspect that it is because you are now saving as pdf and the instruction to close is not running because the original word document has not been saved

    If you do not want to save the Word document then amend the line to
    Please Login or Register  to view this content.
    If you do want to save the word document then go back to your original code and insert the new code in the line immediately above
    Please Login or Register  to view this content.
    New code:
    Please Login or Register  to view this content.
    It will run this code first and create the pdf, and then re-use the same variables with the correct values for saving as word document

  5. #5
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Code to save a word doc to pdf

    Hi Kevin,

    The code looks like this now.
    Please see below.
    If I move the close phrase above the saving as pdf the macro can't save the report as pdf, or I am wrong?

    Please Login or Register  to view this content.

    Thank you,
    Ionut

  6. #6
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Code to save a word doc to pdf

    I think our replies crossed in the "ether". Look at post#4

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Code to save a word doc to pdf

    I see you're also carrying on the same discussion in this thread: http://www.excelforum.com/excel-prog...ose-error.html

    Please read the Duplicate Thread policy in rule #5: http://www.excelforum.com/forum-rule...rum-rules.html
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Code to save a word doc to pdf

    Hi Kevin,

    I tried and it seems that is not working like this also.

    Kr,
    Ionut

  9. #9
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Code to save a word doc to pdf

    Hi Kevin,

    The error was due to the fact that i had a comma:

    Please Login or Register  to view this content.
    and corrected versions was:
    Please Login or Register  to view this content.
    thank you for all your help!

    Ionut

  10. #10
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Code to save a word doc to pdf

    No problem
    - and next time own up if you have cross posted - members here are active on several sites!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 02-27-2015, 05:17 AM
  2. Replies: 2
    Last Post: 10-30-2014, 01:49 AM
  3. Replies: 1
    Last Post: 01-18-2014, 09:32 PM
  4. VBA code to split a Word Document and save it with a specified name
    By adil.master in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2013, 10:49 AM
  5. Macro code to peform compare functionality on MS word and save the difference.
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2013, 02:14 AM
  6. How to save excel spreadsheet and word doc with one save
    By CEP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1