Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    May 2002
    Thanked 0 Times in 0 Posts

    Data source filename (2000/SP-3)

    When creating a mail merge main document, I need to be able to capture the name of the data source file (without extension) and insert that name into the main document.


    Main document filename:
    Data source filename: Neighborhood.xls

    Sample text in Letter1:
    "Welcome to Neighborhood!"

    And, the data source will change depending on where we are sending the letters out. It would be nice to prompt the current user for the data source as soon as they open the template. (I know these are two separate questions. Help on either or both is much appreciated)

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Los Angeles Area, California, USA
    Thanked 0 Times in 0 Posts

    Re: Data source filename (2000/SP-3)

    <P ID="edit" class=small>(Edited by Phil Rabichow on 06-Feb-03 12:19. to add last paragraph)</P>One of the VBA experts could probably be more helpful, but in the meantime...

    You could put the filename without the extension in the title of the property dialog box. If you use Letter1 as the title, then

    {DocProperty Title}

    will give you the name Letter1. The curly brackets are inserted by using Ctrl+F9. To prompt the user, you could use an ASK field, but I haven't tested this with the DocProperty field. Maybe this will give you some ideas, unless someone comes along with a better idea.

    I just re-read your original post. Forget what I said about an ASK field; I misunderstood your question. When you say you want the user prompted for a Data Source when they open the template, I assume you mean open the main document. I think you would be able to do this with an AutoOpen macro that prompted the user for the Data Source in the Mail Merge dialog box. However, one of the VBA experts would have to jump in for that.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Thanked 7 Times in 7 Posts

    Re: Data source filename (2000/SP-3)

    To add the name of the mail merge data source to the beginning of your document you can use something like this in an AutoNew macro

    With ActiveDocument.MailMerge
    If .State = wdMainAndDataSource Then
    ActiveDocument.Content.InsertBefore "Welcome to " & .DataSource.Name
    End If
    End With


  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Evergreen, CO, USA
    Thanked 65 Times in 64 Posts

    Re: Data source filename (2000/SP-3)

    I'm not sure I understand what you mean by putting the data source file name in the main document. Are you trying to make it appear as text in the resulting merge document? If not, and it changes each time, then it doesn't seem you would want to save it as a part of the main document. On the other hand, I could see it appearing in the footer or something in a merged result document.

    If you want to have the document prompt each time for the data source, set the data source, save the document, then delete the source document, and reopen the main merge document. It will say it can't find the document, and as if you want to try to find it, or you can remove the data source. Choose the latter, and then save the document that way. You can also do the same thing in VBA by setting the data source property to an empty string. The property MailMergeDataSource contains the name of the data source document, and can be displayed, printed, or manipulated in VBA. The help files for VBA give some examples of how to do that. You can also set the property at the time you open a document with a VBA command something like:
    <font color=blue> .ActiveDocument.MailMerge.OpenDataSource Name:=strDBName, _
    LinkToSource:=True, Connection:=strQuery, _
    SubType:=wdMergeSubTypeWord2000</font color=blue>
    In this case an Access query is being used to drive the mail merge and the path to the database and query is being supplied. See WAW Vol 3 No. 20 for more details about this. We also have a tutorial about Word merges on our web site. Hope this helps.

Posting Permissions

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