+ Reply to Thread
Results 1 to 2 of 2

VBA Code to Convert/Print Selected Pages of Word Document to PDF File

  1. #1
    Registered User
    Join Date
    07-12-2005
    Location
    Canberra, Australia
    MS-Off Ver
    2007
    Posts
    43

    VBA Code to Convert/Print Selected Pages of Word Document to PDF File

    The code below creates a PDF file from Excel of a Word document. The name of the file is exactly the same except it has a 'pdf' extension rather than 'docx'. The ", 17" at the end of the last line of code gives it the 'pdf' extension.
    The file is 3 pages.
    The main thing I would like to do is create 2 PDF files - one is of just the first page and the other is of pages 2-3.
    I don't know what the code is to specify page ranges.
    The other thing I would like to do is suppress the message that comes up when the second from last line of code is executed - i.e. the one that opens the Word file. It currently says the file is locked for editing and has 3 options for opening the file. I just want to open the file as read-only (which is option 1).
    Also can you tell me how to add this code properly to the thread? At the moment I have just pasted it in from the VBA editor.

    Many thanks
    David

    Sub Create_PDF_File_of_Word_Document()

    Dim wordFile As Object
    Set wordFile = CreateObject("Word.Application")

    Directory_Path = "C:\Data"
    Filename = "Jul-15 Variance Analysis.docx"

    Set wordDoc = wordFile.Documents.Open(Directory_Path & "\" & Filename)

    wordDoc.ExportAsFixedFormat Left(wordDoc.FullName, InStrRev(wordDoc.FullName, ".") - 1), 17

    End Sub

  2. #2
    Registered User
    Join Date
    07-12-2005
    Location
    Canberra, Australia
    MS-Off Ver
    2007
    Posts
    43

    Re: VBA Code to Convert/Print Selected Pages of Word Document to PDF File

    Hi Pan,

    Yes I did. The solution that Paul Edstein aka "macropod" provided worked perfectly. But I'm sorry I do not have any experience in converting pdf to bmp.

    Good luck with finding a solution for your problem.

    Regards,
    David

+ 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: 0
    Last Post: 05-29-2015, 02:25 AM
  2. With excel to print a selected page from a word document
    By eb4927 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-15-2014, 05:54 PM
  3. VBA code to merge text file in a word document and print all the letters automatically
    By Rajbrinder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2013, 08:25 AM
  4. Print off the word document using excel vba code
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2013, 09:42 AM
  5. Extract pages from word file and save extracted pages to new word file
    By bonny24tycoon in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2012, 09:45 AM
  6. Printing selected pages in a Word document
    By Tristan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2006, 08:45 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