PDA

View Full Version : Multi-line Word Variables



Peter Bond
06-07-2005, 03:21 AM
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 ?:banghead:

sandam
06-07-2005, 05:54 AM
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.

Peter Bond
06-07-2005, 07:01 AM
I'm using {DOCVARIABLE "Address" \* MERGEFORMAT }

sandam
06-07-2005, 07:12 AM
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..

Peter Bond
06-07-2005, 07:19 AM
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.

sandam
06-07-2005, 07:45 AM
change the vbCrLf to Chr(13) - its seemed to work for me (this is using Word 2003)

sandam
06-07-2005, 07:47 AM
also, try updateing the field each time you change the value


Selection.Document.Variables.Item("Address").Value = "String 1" & Chr(13) & "String 2"
Selection.Fields.Update

Peter Bond
06-07-2005, 08:52 AM
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.

sandam
06-07-2005, 08:58 AM
No problem :)

MOS MASTER
06-07-2005, 09:40 AM
Hi and Welcome to VBAX! :hi:

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:

vbCr

'Or

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

Later..:whistle:

MOS MASTER
06-07-2005, 09:45 AM
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

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. :whistle:

Peter Bond
06-09-2005, 05:32 AM
Yes I already tried vbcr and vbnewline !!

MOS MASTER
06-09-2005, 09:32 AM
Yes I already tried vbcr and vbnewline !!
Ok I'll try it out myself in 2000! :yes (didn't have time yet)