PDA

View Full Version : copy text without paragraph number



BobSundquist
04-24-2017, 12:53 PM
If a paragraph has automatic numbering enabled, when I try to copy text starting at the beginning of the paragraph, Word always includes the paragraph number. Is there a way to change this behavior?

macropod
04-24-2017, 04:26 PM
Exclude the paragraph break from what you're copying and, if you're using 'Paste Special', try to avoid the 'Text only' option; even that, however, will eventually clear the auto-number content so you can paste without getting the number.

BobSundquist
04-24-2017, 06:12 PM
I didn't include the paragraph break. I copied the first word of a paragraph, without selecting the paragraph number (I don't think I could have explicitly selected that), and pasted into an application that can only accept text, and it gave me the paragraph number along with the first word. This has been a problem with Word (also Outlook) for years, I just wondered if anyone had found a solution.

gmaxey
04-24-2017, 06:30 PM
It doesn't appear that your question is specifically VBA related. Here is, a perhaps crude, VBA method:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Set oRng = Selection.Range
With oRng
.Paste
.ListFormat.RemoveNumbers
End With
lbl_Exit:
Exit Sub

End Sub

macropod
04-24-2017, 06:55 PM
I copied the first word of a paragraph, without selecting the paragraph number (I don't think I could have explicitly selected that), and pasted into an application that can only accept text, and it gave me the paragraph number along with the first word.
If you're copying & pasting manually into another application, you're pretty much at the mercy of how that application interprets what's been copied. And, as you've discovered, Word attaches the auto-number & tab to the first 'real' character of the paragraph.

In order to facilitate copying the text without the auto number, you might use a macro like the following and assign it to a keyboard shortcut.

Sub PlainCopy()
Application.ScreenUpdating = False
With Selection
If .End = .Paragraphs.Last.Range.End Then
.End = .End - 1
End If
If .Start = .Paragraphs.First.Range.Start Then
If .Paragraphs.First.Range.ListFormat.ListString <> "" Then
.Paragraphs.First.Range.ListFormat.RemoveNumbers
.Copy
ActiveDocument.Undo
End If
End If
End With
Application.ScreenUpdating = True
End Sub

BobSundquist
04-25-2017, 08:16 AM
Thanks, that's helpful. I changed it a bit:


Sub PlainCopy()
With Selection
If .Start = .Paragraphs.First.Range.Start And .Paragraphs.First.Range.ListFormat.ListString <> "" Then
Application.ScreenUpdating = False
.Paragraphs.First.Range.ListFormat.RemoveNumbers
.Copy
ActiveDocument.Undo
Application.ScreenUpdating = True
Else
.Copy
End If
End With
End Sub

I took out the part about including the paragraph mark at the end, if I select that I intend to get the whole thing, it was selecting text just at the beginning of the paragraph that bugged me. And I added an else clause because your original code wouldn't copy if it wasn't the start of a numbered paragraph. Then I assigned it to Ctrl-Insert.
Thanks!

Boris_R
04-28-2017, 01:49 AM
If a paragraph has automatic numbering enabled, when I try to copy text starting at the beginning of the paragraph, Word always includes the paragraph number. Is there a way to change this behavior?
And such macro from one code line can't be the decision?

Sub NotKeepBulletsAndNumbers()
Options.PasteOptionKeepBulletsAndNumbers = False
End Sub

After execution of a macro the behavior of Word will change as you want

macropod
04-28-2017, 05:45 AM
If you read the thread, what the OP wants to do is copy an auto-numbered paragraph without the number for pasting into another program. Changing Word's paste options won't achieve that.