+ Reply to Thread
Results 1 to 10 of 10

Excel VBA to convert word file to pdf

  1. #1
    Registered User
    Join Date
    10-09-2017
    Location
    IDN
    MS-Off Ver
    2007 & 2010 & 2013
    Posts
    48

    Excel VBA to convert word file to pdf

    Hy all,

    happy 2018

    i have question about VBA code.

    is it possible to convert word file to PDF using VBA excel?

    in the attached file as seen bellow

    Untitled.jpg

    the word file path is where the word file location, PDF file path is where will PDF saved, and PDF file name is the name of converted PDF.

    so converting, path location and the name of the PDF file is using PDF?

    thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,021

    Re: Excel VBA to convert word file to pdf

    .
    Here are a few resources that will hopefully get you started in the right direction :

    https://stackoverflow.com/questions/...to-pdf-convert

    https://www.thespreadsheetguru.com/t...in-same-folder

    https://sebnilsson.com/blog/microsof...-to-pdf-files/

    http://www.msofficeforums.com/word-v...-into-pdf.html

  3. #3
    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: Excel VBA to convert word file to pdf

    Your screenshot suggests the PDFs will have the same names & extensions as the documents. Don't do that! At least your attached workbook has the correct extensions. Try:
    Please Login or Register  to view this content.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Registered User
    Join Date
    10-09-2017
    Location
    IDN
    MS-Off Ver
    2007 & 2010 & 2013
    Posts
    48

    Re: Excel VBA to convert word file to pdf

    sorry, that's my fault, forget to change the extension of PDF file

    i'd try your code, but error:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-09-2017
    Location
    IDN
    MS-Off Ver
    2007 & 2010 & 2013
    Posts
    48

    Re: Excel VBA to convert word file to pdf

    it says that the word file is locked for editing. but i think i don't locked the file
    do you know why it's locked?

  6. #6
    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: Excel VBA to convert word file to pdf

    OK, change that line to:
    Please Login or Register  to view this content.

  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: Excel VBA to convert word file to pdf

    Quote Originally Posted by adekinteristi View Post
    it says that the word file is locked for editing. but i think i don't locked the file
    do you know why it's locked?
    You probably have an orphaned Word session that still has a document open. Close Word, then use the Task Manager to kill all remaining Word sessions.

  8. #8
    Registered User
    Join Date
    10-09-2017
    Location
    IDN
    MS-Off Ver
    2007 & 2010 & 2013
    Posts
    48

    Re: Excel VBA to convert word file to pdf

    still won't work

  9. #9
    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: Excel VBA to convert word file to pdf

    It does for me...

    Check that your file paths & names are correct.

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Excel VBA to convert word file to pdf

    The code is using early binding. Make sure you have set reference to MS Word Object Library in References. Otherwise wdFormatPDF is unknown to excel (i.e. that is constant from Word object model)
    see https://support.microsoft.com/en-us/...-in-automation
    If you are pleased with a member's answer then use the Star icon to rate it.

+ 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. Convert word or text file to Excel
    By Allgermanparts in forum Excel General
    Replies: 2
    Last Post: 05-25-2013, 02:13 PM
  2. Convert Word file to Excel database
    By ammoun in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2007, 09:09 AM
  3. how to convert word file to excel file
    By MS Foo in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-25-2006, 03:26 AM
  4. convert a .dat file opened in Word to excel?
    By JPM in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-25-2005, 06:30 PM
  5. how to convert word file into excel file
    By Rizwan in forum Excel General
    Replies: 2
    Last Post: 09-16-2005, 01:05 AM
  6. Convert MS Word Lables to an Excel data file
    By brianperryftl in forum Excel General
    Replies: 1
    Last Post: 03-07-2005, 11:04 PM
  7. Replies: 0
    Last Post: 02-28-2005, 06:11 AM

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