Results 1 to 8 of 8

How to save Word documents as PDFs using Excel macro?

Threaded View

  1. #1
    Registered User
    Join Date
    01-22-2017
    Location
    Texas
    MS-Off Ver
    14.7.1
    Posts
    4

    How to save Word documents as PDFs using Excel macro?

    Hi all,

    I am having trouble saving Word documents that I am opening and manipulating through an Excel macro as a .pdf. I've tried several ways and it is not working.
    Right now it kind of works, but it asks me to save the changes for each file. I am looping this macro through several files so this is not convenient for me. Thanks for your help!

    Dim wdApp As Object
    Dim wdDoc As Object
    Dim fileloc As String
        
    fileloc = "Macintosh HD:Users:X:Y:Z.docx" 'Replaced folder names with X Y Z for simplicity
        
    Set wdApp = CreateObject("Word.Application")
    Set wdDoc = wdApp.Documents.Open _
          (Filename:=fileloc)
    
    ***      
    *several lines of code where I manipulate the word doc*
    ***
    
    wdDoc.SaveAs Filename:="Macintosh HD:Users:X:Y:ZZ.docx" 
    
    'Saves files as pdf but asks to accept for each file    
    With Dialogs(wdDialogFileSaveAs)
         .Format = wdFormatPDF
         .Show
    End With
    
    wdDoc.Close savechanges:=False
    Set wdDoc = Nothing
    wdApp.Quit
    Set wdApp = Nothing
    I have tried using wdDoc.ExportAsFixedFormat a few different ways and it hasn't worked.

        wdDoc.ExportAsFixedFormat OutputFileName:= _
            Replace(wdDoc.FullName, ".docx", ".pdf"), _
            ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
            wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False
      wdDoc.SaveAs2 Filename:="Text.pdf", _
            FileFormat:=wdFormatPDF
     
    wdDoc.ExportAsFixedFormat OutputFileName:="Macintosh HD:Users:X:Y:ZZ.pdf", _
          ExportFormat:=wdExportFormatPDF
    EDIT: I do have the Microsoft Word Object Library enabled in references on excel
    Last edited by utexas24; 01-22-2017 at 06:40 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel VBA to open/save MS Word documents
    By Summer7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2017, 10:59 AM
  2. Macro to save documents generated with word/excel automatically
    By kees89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2014, 02:17 PM
  3. [SOLVED] Macro for mail merge and save as word documents
    By aganesan99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2013, 09:16 AM
  4. [SOLVED] Using Excel Macro to Print Word Documents
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-26-2013, 01:15 AM
  5. Macro to save excel worksheets as pdfs and change hyperlinks to work in pdf format
    By crnadeau4 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2013, 12:18 PM
  6. Macro Needed to Loop, Save, and Name Excel Files as PDFs
    By ahkarchem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2012, 10:46 AM
  7. Open and Save Word Documents via Excel
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-22-2010, 02:54 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