Consulting

Results 1 to 9 of 9

Thread: Running ActiveDocument.ConvertNumbersToText removes bold font emphasis

  1. #1
    VBAX Regular
    Joined
    Oct 2023
    Posts
    8
    Location

    Running ActiveDocument.ConvertNumbersToText removes bold font emphasis

    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?

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Oct 2023
    Posts
    8
    Location
    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.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular
    Joined
    Oct 2023
    Posts
    8
    Location
    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

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Regular
    Joined
    Oct 2023
    Posts
    8
    Location
    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
    Last edited by Aussiebear; 10-30-2023 at 06:13 AM. Reason: removed the unnecessary quotation

  8. #8
    VBAX Regular
    Joined
    Oct 2023
    Posts
    8
    Location
    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
    Last edited by Aussiebear; 10-30-2023 at 06:14 AM. Reason: removed the unnecessary quotation

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •