Consulting

Results 1 to 13 of 13

Thread: Multi-line Word Variables

  1. #1

    Question Multi-line Word Variables

    I am using VB to open a Word document which contains Word Variable markers - e.g. for contact names and addresses. As the number of contacts and address lines is not fixed, I need to pass strings into the variables which are multi-line. In other words they are constructed like this :
    Var1="Line 1" & vbcrlf & "Line 2" & vbcrlf etc.

    This is all very well but when Word substitutes the text it displays the Carriage Return/Line Feed pairs as 'box' symbols and the text doesn't wrap - it's all on a single line.

    Has anyone else encountered this problem and found a solution ?

  2. #2
    Knowledge Base Approver
    Space Cadet
    VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    Hi and welcome to VBAX

    what are you displaying the variable with? if its a textbox then you need to set multiple lines to true on the properties.
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  3. #3
    I'm using {DOCVARIABLE "Address" \* MERGEFORMAT }

  4. #4
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    try changing the vbcrlf to vblf. vbCrLf in english means Carriage return and Line Feed. It also did the same thing to me in a macro I was working on. Expecially when pulling text out of tables (ths is when it happened to me..
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  5. #5
    I've already tried vbcr and vblf separately, but to no avail. I notice though that if I put a hard carriage return (new para) in the actual document after the {DOCVARIABLE "Address" \* MERGEFORMAT }, everything appears OK.

  6. #6
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    change the vbCrLf to Chr(13) - its seemed to work for me (this is using Word 2003)
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  7. #7
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    also, try updateing the field each time you change the value

    [vba]
    Selection.Document.Variables.Item("Address").Value = "String 1" & Chr(13) & "String 2"
    Selection.Fields.Update
    [/vba]
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  8. #8
    That doesn't work either. Maybe it's a "feature" of Word 2000. Anyway, as long as as I can get round it by adding the carriage return in the document, that will do for now.
    Thanks very much for your help.

  9. #9
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    No problem
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  10. #10
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi and Welcome to VBAX!

    This is strange indead and interesting the same time. I'll have to test this on a 2000 machine later.

    Could you also try as to the many you've used allready:
    [VBA]
    vbCr

    'Or

    vbNewLine [/VBA]
    You never know...Like andy I wasn't able to reproduce this behaviour in 2002 & 2003.

    Later..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Peter Bond
    That doesn't work either. Maybe it's a "feature" of Word 2000. Anyway, as long as as I can get round it by adding the carriage return in the document, that will do for now.
    Thanks very much for your help.
    Hi Peter,

    Yes this will help you for a short time.

    But the problem is you're calling the document variable from a field and when that field gets updated the Carriage return will be gone! (Try: Select and press F9)

    That's because you aren't changing the actual value of the variable but the fieldresult which isn't the same thing.

    Will try to find out what the problem could be with Word 2000.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    Yes I already tried vbcr and vbnewline !!

  13. #13
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Peter Bond
    Yes I already tried vbcr and vbnewline !!
    Ok I'll try it out myself in 2000! (didn't have time yet)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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