I need to create a macro that will convert some automatically numbered lists to plain text. I found this macro below which will do the whole document perfectly, however I wish to keep the document titles etc still numbered automatically and just change the numbered list of requirements in the document to plain text.
Sub Auto_Format_convert_list_numbers()
'
' convert_list_numbers Macro
' Macro created 10/8/08 by WJ Shack
'
ActiveDocument.ConvertNumbersToText
End Sub
My thoughts on the subject were perhaps I could have it only do this to a list i have selected. (When i click on one of the numbered items it kind of highlights the others in the list) I tried the following but it gets an error
Sub Auto_Format_convert_list_numbers()
'
' convert_list_numbers Macro
' Macro created 10/8/08 by WJ Shack
'
Selection.ConvertNumbersToText
End Sub
Any suggestions? (I will keep pondering it myself but i'm sure as the whole document option is so simple there must be an easy way to do this!)
The ConvertNumbersToText
method isn't valid for Selection
, but does work for the List
class, so this sub will convert each List in the ActiveDocument
:
Sub Auto_Format_convert_list_numbers()
Set RE = CreateObject("vbscript.regexp")
'Change your pattern here
RE.Pattern = "[A-Z][A-z][0-9][0-9][-][0-9]"
For Each Lst In ActiveDocument.Lists
Set Match = RE.Execute(Lst.Range.Text)
If Match.Count Then
Lst.ConvertNumbersToText
End If
Next
End Sub
If you want to convert just your Headings to text, this will do it for the entire document:
Sub ConvertHeadingNumbersToText()
Dim paraCount As Integer
paraCount = ActiveDocument.Paragraphs.Count
Dim text As String
Dim para As Paragraph
' process the headings bottoms up to preserve their original numbers
For i = paraCount To 1 Step -1
Set para = ActiveDocument.Paragraphs(i)
If InStr(1, para.Style, "Heading") Then
para.Range.ListFormat.ConvertNumbersToText
text = para.Range.text ' add a Watch for text so you can see progress in the Watches window
End If
Next i
End Sub
Today I had exactly the same problem as OP, and come up with a simple solution:
Sub Selection_Convert_List_Numbers()
Selection.Range.ListFormat.ConvertNumbersToText
End Sub