none
Save Document with specific name RRS feed

  • Question

  • I am creating a WinForm to generate documents and want to have the documents saved as a PDF with a specific file name structure. How do I go about naming the document?

    Thank you for any information, resources or sample code.


    -----
    MrStu
    Worse than a newbie, the business guy who wants to code...
    Tuesday, December 28, 2010 8:08 PM

Answers

  • Hi Mr. Stu

    The ExportAsFixedFormat method has a lot of parameters. Here's the 2007 version of it (2010 would be the same, or have additional options at the end):

    Sub ExportAsFixedFormat(OutputFileName As String, ExportFormat As WdExportFormat, [OpenAfterExport As Boolean = False], [OptimizeFor As WdExportOptimizeFor = wdExportOptimizeForPrint], [Range As WdExportRange = wdExportAllDocument], [From As Long = 1], [To As Long = 1], [Item As WdExportItem = wdExportDocumentContent], [IncludeDocProps As Boolean = False], [KeepIRM As Boolean = True], [CreateBookmarks As WdExportCreateBookmarks = wdExportCreateNoBookmarks], [DocStructureTags As Boolean = True], [BitmapMissingFonts As Boolean = True], [UseISO19005_1 As Boolean = False], [FixedFormatExtClassPtr])

    It looks to me as if all you need to do is add the file name as a string before the two parameters you're already specifying...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Stu Ryan Monday, January 3, 2011 7:34 PM
    Tuesday, December 28, 2010 9:50 PM
    Moderator

All replies

  • Hi Mr. Stu

    Are you familiar with the Document.SaveAs method from your work with VBA? That's the way to go, no matter which programming language - assuming we're talking about Word 2007 / 2010. Those are the only two versions that can "save as" PDF. In earlier versions it was usually necessary to print to a file using a PDF "driver"...

    In case you need a code sample, please remind us which programming language you're using?


    Cindy Meister, VSTO/Word MVP
    Tuesday, December 28, 2010 8:52 PM
    Moderator
  • Hello Cindy,

    Thanks for the reply, I am using VB.NET (.NET 4.0), VS2010 Professional, and Office 2010...

    I have the save part done and I am using wdDoc.ExportAsFixedFormat(wdExportFP, wdExportAsPDF) to save as PDF to a specific location. I am just not understanding how to name the document.

     

    btw - I have made a lot of progress on my document generator since you helped me understand how to use insertfile. Thanks again for the help.


    -----
    MrStu
    Worse than a newbie, the business guy who wants to code...
    Tuesday, December 28, 2010 9:33 PM
  • Hi Mr. Stu

    The ExportAsFixedFormat method has a lot of parameters. Here's the 2007 version of it (2010 would be the same, or have additional options at the end):

    Sub ExportAsFixedFormat(OutputFileName As String, ExportFormat As WdExportFormat, [OpenAfterExport As Boolean = False], [OptimizeFor As WdExportOptimizeFor = wdExportOptimizeForPrint], [Range As WdExportRange = wdExportAllDocument], [From As Long = 1], [To As Long = 1], [Item As WdExportItem = wdExportDocumentContent], [IncludeDocProps As Boolean = False], [KeepIRM As Boolean = True], [CreateBookmarks As WdExportCreateBookmarks = wdExportCreateNoBookmarks], [DocStructureTags As Boolean = True], [BitmapMissingFonts As Boolean = True], [UseISO19005_1 As Boolean = False], [FixedFormatExtClassPtr])

    It looks to me as if all you need to do is add the file name as a string before the two parameters you're already specifying...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Stu Ryan Monday, January 3, 2011 7:34 PM
    Tuesday, December 28, 2010 9:50 PM
    Moderator
  • Cindy,

    Thanks, I will work on this...


    -----
    MrStu
    Worse than a newbie, the business guy who wants to code...
    Thursday, December 30, 2010 3:25 PM
  • Cindy,

    Took a little bit of working on this, but I finally got it working. I also found a bit of code that helped me see what I was doing wrong.

    The sample code is here - http://msdn.microsoft.com/en-us/library/bb412305.aspx

     

    Thanks again for all the help over the last couple of weeks.


    -----
    MrStu
    Worse than a newbie, the business guy who wants to code...
    Monday, January 3, 2011 7:39 PM