PDA

View Full Version : Running ActiveDocument.ConvertNumbersToText removes bold font emphasis



Jeff_VB
10-27-2023, 09:38 AM
Hi,
we use Word to list numbered command entry. As such, copying the commands from auto-numbered lines also copies the number, period and space or tab. So, when we paste in a command from Word to Putty for example, the commands starts with the unwanted number. I know this is a common problem. I thought the work-around using ConvertNumbersToText was at least a workaround, but if I have bold text, it removes the bold emphasis when it converts to text. Is there a way to preserve the font/size attributes when running it?

gmaxey
10-28-2023, 02:15 AM
Not seeing that behaviour here but maybe one of these will help:


Sub ScratchMacro()
Dim oPar As Paragraph
Dim strNum As String
Dim lngIndex As Long
For lngIndex = ActiveDocument.Range.Paragraphs.Count To 1 Step -1
Set oPar = ActiveDocument.Range.Paragraphs(lngIndex)
strNum = oPar.Range.ListFormat.ListString
oPar.Range.ListFormat.RemoveNumbers
oPar.Range.InsertBefore strNum & vbTab
Next lngIndex
End Sub
Sub ScratchMacroII()
Dim oPar As Paragraph
For Each oPar In ActiveDocument.Paragraphs
oPar.Range.ListFormat.RemoveNumbers
Next oPar
End Sub

Jeff_VB
10-28-2023, 04:57 AM
Thanks, but I didn't want the numbers removed. I'm going to create a separate thread for the solution that I came up with.

gmaxey
10-28-2023, 05:48 AM
Jeff, the first macro I posted doesn't remove the numbers. Well, it does but then it puts them back as text.


Sub ScratchMacro()
Dim oPar As Paragraph
Dim strNum As String
Dim lngIndex As Long
For lngIndex = ActiveDocument.Range.Paragraphs.Count To 1 Step -1
Set oPar = ActiveDocument.Range.Paragraphs(lngIndex)
strNum = oPar.Range.ListFormat.ListString
oPar.Range.ListFormat.RemoveNumbers
oPar.Range.InsertBefore strNum & vbTab
Next lngIndex
End Sub

Jeff_VB
10-28-2023, 07:58 AM
Hi Greg,
the first one err'd on me so I tried only the second one. But since I created this thread, I ended up creating a workaround that I like and that is here:
How-not-to-copy-line-numbers-when-select-text-from-auto-numbered-lines
post 421554
I tried to copy the url, but this website didn't like it.

Thank you,

Jeff

gmaxey
10-28-2023, 08:39 AM
Jeff,

Your work around seems like a lot of effort. Now that I have a better idea what you are trying to do, how about:


Sub CopyListParagraphWithTheNumber()
Dim oPar As Paragraph
Set oPar = Selection.Paragraphs(1)
oPar.Range.ListFormat.RemoveNumbers
oPar.Range.Copy
ActiveDocument.Undo 1
lbl_Exit:
Exit Sub
End Sub


Assign your shortcut to that. After running, paste into your new document or whatever.

Jeff_VB
10-28-2023, 09:06 AM
No effort after it was done.
I just pointed out to folks that you have to be careful how you select the text.
But this is the first method I've found that actually works.
I'll try yours though as I'm always up for learning options.
Thx

Jeff_VB
10-28-2023, 09:14 AM
Sorry, but either I'm not understanding how to use your code, or it's just not working.
You said "After running, paste into your new document or whatever."
So, I had a test list of three auto-numbered lines. I ran your code, then selected text on one of the lines and copied into notepad. It copied the number, period, and space along with the text just like the original problem.
Then I selected all three lines, and ran your macro. Tried the same copy and got the same results. Is there some other way to run it?

Thanks,
Jeff

gmaxey
10-30-2023, 06:01 AM
Jeff,
Put the cursor anywhere in the line your want to copy and execute the macro (you can assign your shortcut to it). This copies the text without the list string (number, period and tab) to the clipboard. Paste it anywhere you want to paste.