Carriage returns to Plain Text loses formatting

C

corky_guy

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

Russ

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
 
C

corky_guy

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

Russ

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.¶
 
D

David Sisson

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

Russ

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
 
R

Russ

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.
 

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