Results 1 to 7 of 7

Thread: SAVEAS PDF and Word 2016 and WIndows 10

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    SAVEAS PDF and Word 2016 and WIndows 10

    Hello.. In Word 2010 and 2013 we were able to save a word document as a PDF. Now along comes 2016 and it no longer works.

    This is my function which works great for 2010 and 2013.

    Function Convert_To_PDF() As Boolean
    Dim NewFileName As String
    Dim fileFormat As String
    oWord = CreateObject("Word.Application")
    If ExtType = "DOCX" Then
    NewFileName = PathSaveTo.Replace(".docx", ".pdf")
    Else
    NewFileName = PathSaveTo.Replace(".doc", ".pdf")
    End If
    fileFormat = Word.WdSaveFormat.wdFormatPDF
    oDoc = oWord.Documents.Open(PathIn)
    Dim newdoc As Word.Document
    newdoc = oDoc
    newdoc.SaveAs2(NewFileName, Word.WdSaveFormat.wdFormatPDF)
    oWord.ActiveDocument.Close(False)
    oWord.Quit()
    PathSaveTo = NewFileName
    Return True
    End Function

    What's up with 2016? Is there a work-a-round that will function with 2010 and 2013 AND 2016 ??

    Thank you

    gollnick
    William E Gollnick

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    Quote Originally Posted by gollnick View Post
    it no longer works.
    Can you elaborate? What actually does happen? That is always relevant information. Have you consulted the relevant documentation for the Word 2016 object model?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    Quote Originally Posted by jmcilhinney View Post
    Can you elaborate? What actually does happen? That is always relevant information. Have you consulted the relevant documentation for the Word 2016 object model?
    Opps..sorry... it just goes out to lunch and never returns to the next line of code. From what I have gleaned from the 2016 documents the saveas to a pdf is no longer supported... ??
    Gollnick
    William E Gollnick

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    I don't really use Office Interop myself so all I can tell you is that Word itself (I'm using Office 365 but I would expect Office 2016 to be the same) does still support saving a document to a PDF file.

    I searched for "word 2016 interop save pdf" and one of the results I found was this:

    https://www.codeproject.com/question...-pdf-in-csharp

    One of the solutions there does this:
    csharp Code:
    1. wordDocument.ExportAsFixedFormat(@"D:\desktop\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
    You might try that ExportAsFixedFormat method instead of SaveAs2. It doesn't mention versions and it was posted some time ago (before 2016), but it may be worth a try.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    By the way, you should use the Path class to manipulate file and folder paths. Path.ChangeExtension is one method that is relevant to you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    This page:

    https://www.ryadel.com/en/programmat...et-c-doc-docx/

    says this:
    Here’s a brief example showing what you can do:
    csharp Code:
    1. // NS alias to avoid writing the required namespace all the time
    2. using word = Microsoft.Office.Interop.Word;
    3.  
    4. // [...]
    5.  
    6. Application app = new word.Application();
    7. Document doc = app.Documents.Open(filePath);
    8.  
    9. doc.SaveAs2("path-to-pdf-file.pdf", word.WdSaveFormat.wdFormatPDF);
    10. doc.Close();
    11. app.Quit();
    Alternatively, if you don’t like the SaveAs2 method, you can use the ExportAsFixedFormat() method instead and achieve a nearly identical result:
    csharp Code:
    1. doc.ExportAsFixedFormat(tmpFile, WdExportFormat.wdExportFormatPDF);
    so it looks like you should be able to call ExportAsFixedFormat, but then it looks like you should be able to call SaveAs2 as well. That page is dated 2017 so should be relatively current.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: SAVEAS PDF and Word 2016 and WIndows 10

    Recording a macro whilst saving as PDF in Word 2016 produced this:

    Code:
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
            "C:\Users\Paul\Desktop\Test1.pdf", ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
            wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
            IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
            wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
            True, UseISO19005_1:=False
        ChangeFileOpenDirectory "C:\Users\Paul\Desktop\"
    ... so something like post #4 may be near the mark.

Posting Permissions

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



Click Here to Expand Forum to Full Width