Consulting

Results 1 to 12 of 12

Thread: Need the Word 2010 vba equivalent of merge command

  1. #1
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location

    Smile Need the Word 2010 vba equivalent of merge command

    Hello all,

    I need the word 2010 vba equivalent of this type of command:
    [code]
    'preRRPolicies$ = preRRPolicies$ + WordBasic.[GetMergeField$]("Pre_RR_Contracts_for_Addressee")
    p/code]

    What does the plus sign do?

    Any and all help is greatly appreciated!

    Kurt

  2. #2
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location
    Can someone tell me what the plus sign does? I think it is trying to add a field and I am researching the syntax in word 2010 vba. I really need some help on this thanks!

  3. #3
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location
    I am trying this but I get red meaning an error of course:

    pensionPolicies$ = ActiveDocument.MailMerge.Fields.Add, Range:=Selection.Range,"pensionPolicies"

  4. #4
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location
    Am I on the right track here?

    I found this while doing a search in Word 2010 on Add Field which is what I think the plus sign does.

    With ActiveDocument
        .Variables.Add Name:="pensionPolicies$"
        .Fields.Add Range:=Selection.Range, Type:=wdFieldDocVariable, Text:="pensionPolicies"
    End With
    Anyone wiht anything would be greatly appreciated!

  5. #5
    VBAX Regular
    Joined
    Feb 2010
    Posts
    11
    Location
    Don't know if this is what your after but the VBA to execute a mail merge is:

    [VBA]
    With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
    .FirstRecord = wdDefaultFirstRecord
    .LastRecord = wdDefaultLastRecord
    End With
    .Execute Pause:=False
    End With
    [/VBA]

  6. #6
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location

    Smile

    Ed,

    Thanks for the try, but I don't think that is it.

    Can someone please tell me what the + sign does and its' equivlaent in Word 2010?

    Thanks,

    Kurt

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    The plus sign is the same as the ampersand (&). It concatenates two strings together. It is a Basic term and has nothing specific to do with 2010.

    "yadda" + "blah"

    is the same as

    "yadda" & "blah"

    BOTH = "yaddablah"

    Now it MAY be true that in 2010 VBA no longer recognizes that + and & are the same. I do not know. But in WordBasic (old,old, old) the plus sign was commonly used. Certainly up to 2003 VBA did not care if you used + or &, it was happy with both, or either.

  8. #8
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location
    Yep you are correct!

    I just got off the phone with someone who said the same thing.

    I got it figured out and you just double confirmed it!

    Am I correct in assuming it is looking for the valuable of the variable in the string with the $ ?

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    [vba]'preRRPolicies$ = preRRPolicies$ + WordBasic.[GetMergeField$]("Pre_RR_Contracts_for_Addressee")[/vba]

    means

    The string variable preRRPolicies equals the string variable preRRPolicies with the string value of the merge field Pre_RR_Contracts_for_Addressee added to the end.

    So if preRRPolicies = "yadda", and Pre_RR_Contracts_for_Addressee = "blah"

    preRRPolicies now = "yaddablah"

  10. #10
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...ba-syntax.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  11. #11
    VBAX Regular
    Joined
    Sep 2010
    Posts
    15
    Location
    So is this the correct way to do this in word vba 2010?

    pensionPolicies = pensionPolicies & ActiveDocument.MailMerge.DataSource.DataFields("pensionPolicies").Value

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    Since I have no idea what pensionPolicies is, it is hard to say, but it looks like it should be fine.

Posting Permissions

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