Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Nov 2004
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Auto Filename creation (Word 2000)

    I create documents that consistently have a mergefield date value and two other mergefields that totally define the document. If it is only me that creates the document I know I create a correctly defined name for it but others that may do so are less conscientious and as a consequence when searching for the file name in a fairly large directory the file is lost.
    Is it possible to define the save name using the mergefields together with a constant piece of text ie create a string as the file name?
    I'd appreciate help on how to do it if possible

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto Filename creation (Word 2000)

    We have had a number of threads on pre-populating the Save As dialog's file name field using different kinds of data. This typically is done by "hijacking" the FileSaveAs command. While it can be a bit tricky getting a valid file name when using random data from a document, you can work through those little glitches.

    However, I'm not sure at all of the interplay with merge fields. Are you wanting to name your "main document" or the resulting "merged" document? Only the former is likely to have field codes that could be searched for to assemble the file name.

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

    Re: Auto Filename creation (Word 2000)

    See How to set the default suggested filename to be displayed by the Save As dialog the first time a user saves a new document for an example of code you can use.

    However, Jefferson raises a valid point: the merge document (the one with the merge fields) doesn't necessarily have the values you want, and in the final merged document, the merged values aren't distinguishable from other text. Setting a bookmark around the merge fields won't help - the bookmark will be removed during the merge. Moreover, the merged document might contain multiple records.

  4. #4
    Lounger
    Join Date
    Nov 2004
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Auto Filename creation (Word 2000)

    The merged document that is created from the template is the one that needs saved and there is only ever one merged doc file created at any time.
    The fields are used to fill bookmarks and alter sections throughout the document that is some 31 pages long. (To try and locate and change each one otherwise would be a real nightmare) There is also some date calculation from the date input. There are 3 fields required to define the file name absolutely; these include the date - input format as dd/mm/yy and two text fields.
    The data (doc) file is never saved since the wording of the template file can be and is changed in time.
    Is it possible to interrogate the data file prior to creation of the merged file for a string to insert as the filename?

    NB I did a searches before posting the original but couldn't find previous posts on this topic

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

    Re: Auto Filename creation (Word 2000)

    You could use the following code fragment as starting point. It should be run on the merge document (the one with the merge fields) before completing the mail merge.
    <code>
    Dim strTitle As String
    ' Show field results
    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
    ' Modify the following lines as needed to assemble the suggested filename
    ActiveDocument.MailMerge.Fields(1).Select
    strTitle = Selection.Text
    ActiveDocument.MailMerge.Fields(2).Select
    strTitle = strTitle & " " & Selection.Text
    ' Set the suggested filename
    With Dialogs(wdDialogFileSummaryInfo)
    .Title = strTitle
    .Execute
    End With
    </code>
    You could add code to complete the mail merge.

Posting Permissions

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