<snip of code>
If CheckBox1.Value = "True" Then
ActiveDocument.Variables("protocol").Value = "router bgp 9999" & vbCr
& "address-family ipv4 vrf " _
& "activate" & vbCr & "no auto-summary" & vbCr & "no synchronization"
& vbCr & "exit-address-family"
Else
ActiveDocument.Variables("test").Value = " "
End If
</end snip of code>
If I copy/paste the result from the checkbox into word, it pastes as
it should:
router bgp 64513
address-family ipv4 vrf
activate
no auto-summary
no synchronization
exit-address-family
If I copy/paste the result from the checkbox into anything else (i.e.,
a text editor), it pasts as plain text and the carriage returns are
removed:
router bgp 64513 address-family ipv4 vrf activate no auto-summary no
synchronization exit-address-family
Is there any way to maintain the carriage returns no matter where I am
pasting the output?
Thanks!
Russ - 16 Jul 2007 08:37 GMT
Corky,
You insert a document variable into a document with a field like this
wherever you want, either through the menus or VBA code.
The field code looks like this:
{ DOCVARIABLE "protocol" \* MERGEFORMAT }
If you toggle ALT/F9 between field code and results you should be able to
copy and paste the results in another editor.
Or refer to it with:
ActiveDocument.Variables("protocol").Value
Like this:
Selection.TypeText Text:=ActiveDocument.Variables("protocol").Value
> <snip of code>
>
[quoted text clipped - 30 lines]
>
> Thanks!

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
corky_guy@yahoo.com - 16 Jul 2007 14:07 GMT
Hey Russ -
Everything is making it into the doc correctly. I can even view the
paragraph marks if I toggle the field codes. The problem, though, is
that if I copy and paste the output into Textpad, for example, all of
the carriage returns are removed, and the text pastes as one long
line.
Russ - 16 Jul 2007 19:13 GMT
You shouldn't be seeing paragraph marks in the field *code*, but in the
*results* of field, when you toggle with ALT/F9.
The field code should look like this, if you're not doing anything else to
it:
{ DOCVARIABLE "protocol" \* MERGEFORMAT }
When you toggle the Main Toolbar Show/Hide Button (¶) to show/hide normal
hidden characters, you should see paragraph marks after each paragraph of
text.¶
> Hey Russ -
>
[quoted text clipped - 3 lines]
> the carriage returns are removed, and the text pastes as one long
> line.

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 19 Jul 2007 10:02 GMT
Corky,
I didn't test your example until now, sorry.
I now see what you are saying. The concatenated vbCr
in the field don't act like real paragraph marks and aren't working like
they do in regular text.
I have successfully ran this code over them to change them into real
paragraph marks and then was able to copy and paste into another
application.
Dim objRange As Word.Range
Set objRange = ActiveDocument.Range(0, 0)
ActiveWindow.View.ShowFieldCodes = False
With objRange.Find
.MatchWildcards = True
.Text = "^13"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
> You shouldn't be seeing paragraph marks in the field *code*, but in the
> *results* of field, when you toggle with ALT/F9.
[quoted text clipped - 13 lines]
>> the carriage returns are removed, and the text pastes as one long
>> line.

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 19 Jul 2007 10:26 GMT
Corky,
Experimenting more, shows that you might use vbVerticalTab instead of vbCr
in fields and still be able to copy and paste into another application.
> Corky,
> I didn't test your example until now, sorry.
[quoted text clipped - 32 lines]
>>> the carriage returns are removed, and the text pastes as one long
>>> line.

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
David Sisson - 18 Jul 2007 14:25 GMT
On Jul 15, 10:00 pm, corky_...@yahoo.com wrote:
> If I copy/paste the result from the checkbox into anything else (i.e.,
> a text editor), it pasts as plain text and the carriage returns are
> removed:
>
> Is there any way to maintain the carriage returns no matter where I am
> pasting the output?
When you start another program and paste, you are using that program's
Paste function, not Word's, so you are at the mercy of that programs
interpretation of the data.
Suggestions: (Guesses really)
You might try saving the Word document as a text file.
You could Write the info to a text file.
You might change the vbcr to chr(13), or chr(13) & chr(10). (Carriage
return and linefeed. But I don't think it'll help.)
Maybe, send the data straight to Clipboard. See PutInClipboard method.