Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2004
    Location
    Las Vegas, Nevada, USA
    Posts
    288
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Macro to name and save a file (Word XP/2003)

    Is there a way to use a macro to name and save a Word document to a specific folder on a drive?

    There is often confusion among different people what to name a file and where to save it after completion.
    A macro that would find a name in a specific Text Form field and/or a MergeField, (i.e. Contract 123456),
    Richard Spring

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Macro to name and save a file (Word XP/2003)

    You can use something like this:

    Sub MySave
    ActiveDocument.SaveAs FileName:="C:MyFolderMySubFolder" & _
    ActiveDocument.FormFields("Contract").Result & ".doc"
    End Sub

    In a merged document (the final result of a mail merge), the merge fields have been replaced with their values, so there is no easy way to know what the value of a specific merge field is. In a merge document (a document with merge fields connected to a data source), you must make sure that merge data are displayed; you can then use (for example) ActiveDocument.Fields(3).Result

  3. #3
    3 Star Lounger
    Join Date
    Jan 2004
    Location
    Las Vegas, Nevada, USA
    Posts
    288
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Macro to name and save a file (Word XP/2003)

    Tried the Text Form Field by going to Forms Toolbar - Text Form Field, then right clicking on the inserted Text Field and change the default text to "contract".
    If you run the macro it will save the file as contract.doc, however if you enter a number in the Text Field, the run the macro it does not work. As you stated in the mail merged document once you enter data into the field it changes to that value.
    I tried ActiveDocument.Fields(1).Results and ActiveDocument.TextFormFields(1).Both caused an error message.
    Is there any "container", field or another object that would hold the data and allow it to be run in the macro? In Excel you can use the data within a cell and it works nicely.
    Richard Spring

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Macro to name and save a file (Word XP/2003)

    I tried it with a text form field, and it works fine if I enter a number.

    A merged document has no memory of which parts were originally merge fields. It wouldn't make sense, since a merged document may contain many records.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2004
    Location
    Las Vegas, Nevada, USA
    Posts
    288
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Macro to name and save a file (Word XP/2003)

    Will try the text form field again tomorrow and see if I can duplicate your results.
    Richard Spring

Posting Permissions

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