Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Reorder column list (Word 2003)

    Hi,

    Im amending a mail merge to labels script to reorder column 'Address 2'. Ive recorded the code when doing this at the recipients list stage in a manual mail merge, by simply pressing the relevant column heading. The script is detailed below;

    ActiveDocument.MailMerge.OpenDataSource Name:= _
    "C:testLabels Filelabels.csv", ConfirmConversions:=False, ReadOnly:= _
    False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
    PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= _
    "", Revert:=False, Format:=wdOpenFormatAuto, Connection:="", SQLStatement _
    :="", SQLStatement1:="", SubType:=wdMergeSubTypeOther
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
    wdFieldAddressBlock, Text:= _
    "f ""<<_TITLE0_ >><<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_COMPANY_," & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_" & Chr(13) & ">><<_STATE_" & Chr(13) & ">><<_POSTAL_>><<" & Chr(13) & "_COUNTRY_>>"" l 2057 c 2 e ""U"
    WordBasic.MailMergePropagateLabel

    However when I insert this into the existing script it ignores the column reorder. <img src=/S/confused3.gif border=0 alt=confused3 width=45 height=45>

    All suggestions welcome.

    Cheers.
    Lee

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

    Re: Reorder column list (Word 2003)

    Change
    <code>
    ..., SQLStatement _
    :="", ...
    </code>
    to
    <code>
    ..., SQLStatement _
    :="SELECT * FROM 'labels.csv' ORDER BY Address_2", ...
    </code>
    Note the underscore replacing the space in the field name.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Reorder column list (Word 2003)

    Hi Hans,

    Having copied and paste your code into the right place, word produces a message stating that, ' word was unable to open data source'.

    Not sure why this happened?

    Regards
    Lee

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

    Re: Reorder column list (Word 2003)

    What is the exact name of the column you're trying to sort on?
    If you wish, you can attach a copy of the .csv file (zipped, for the Lounge doesn't accept .csv attachments), with only a few dummy records. That would enable Loungers to experiment.

  5. #5
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Reorder column list (Word 2003)

    The column name on the csv is Address2, without a space. Ive removed the _ from the script I pasted in and all works fine now. <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22>

    Thanks again Hans for all your help.

    Cheers.
    Lee

Posting Permissions

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