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
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