Word 2007 DocVariable losing vbCr on File Close/Open

T

Trevor Henderson

Hello all
I am storing data from a UserForm in a Word 2007 document in DocVariable
fields. Some docvariables are being loaded from multiline textboxes via code
like:
ActiveDocument.Variables.Add "v1", TextBox1.Text

For test data, assume I type in "a" plus ENTER plus "b" into the text box
(without the double quotes) - so my textbox contains an "a" plus a vbCrLf
plus a "b". After running the above Variables.Add line in my OK_click routine
and closing down the userform, I then run this macro to display the contents
of the docvariable (all Dim statements etc removed to keep it short):
Sub aaa()
v = ActiveDocument.Variables("v1")
For i = 1 To Len(v)
s = s & Asc(Mid(v, i, 1)) & " "
Next
MsgBox s
End Sub

As expected, this displays "97 13 10 98". If I now save the document in
native DOCX or DOCM format, close it, reopen it, and then rerun the same
macro, it will now display "97 10 98". The action of closing and re-opening
the document loses the vbCr (i.e. the ascii 13). This is NOT what happens in
earlier versions of Word. Any ideas on how to stop this? All of the
{docvariable v1} field codes in the document display correctly (i.e. show the
paragraph mark) until you close and reopen the document. After reopening the
document the "a" and the "b" will be on the same line - i.e the paragraph
mark is now missing in the document.

C'ya all
Trevor
 
D

Doug Robbins - Word MVP

That's a bit annoying. A work around would be to have an autoopen macro
containing the following code

Dim avar As Variable
For Each avar In ActiveDocument.Variables
avar.Value = Replace(avar.Value, Chr(10), Chr(13))
Next avar


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Trevor Henderson

Hello Doug

Yes, I could do that, but that is an not always going to work. For example,
a user could hold down the Shift key and thereby bypass the autoopen macro.
To me this is a straight out bug in Word. A similar thing happens in the
"Comments" Document Property field - for example, type in a multiline comment
(something containing a hard-return) into the Comments field, put a
{docproperty comments} Field into a Word 2007 document and it will display
your text as entered. Now Save the document, then Close it, and then reopen
it. The contents of the comments field will now be buggered. To me this is
nothing short of a straight out bug in Word.

C'ya
Trevor
 
D

Doug Robbins - Word MVP

You are right that it is a bug and it has been reported as such.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

An alternative work around is to save in Word 97-2003 format. I realise
that also may not be satisfactory.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Trevor Henderson

Thanks for that info Doug. Does your access to this bug list include any
information about if/when Microsoft might fix the issue? For example, are
they giving it any priority and releasing a hotfix or is it something they
have identified but won't be doing anything about or something in between
those two extremes?

C'ya
Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top