ML said:
I need to be able to loop through all paragraphs and bulleted lists
in a document, check the first character to see if it is a marker and
if not insert an autotext item.
What is the easiest way to handle this?
You don't say what your marker character is, so you'll have to modify that
line in the code. You also need to specify the correct name for the autotext
entry that should be inserted.
Sub InsertIfNoMarker()
Dim oPara As Paragraph
Dim Marker As String
Dim oRg As Range
Marker = Chr$(254) ' or whatever you have
' loop through all paragraphs
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.Characters.First <> Marker Then
' create a Range object at the start
' of the paragraph
Set oRg = oPara.Range
oRg.Collapse wdCollapseStart
' insert the autotext there
With ActiveDocument.AttachedTemplate
.AutoTextEntries("entry1").Insert _
Where:=oRg, RichText:=True
End With
End If
Next oPara
' clean up
Set oRg = Nothing
End Sub
Whether or not a paragraph is part of a bulleted list has no effect -- the
bullet is not a character in the paragraph, so the first character is the
letter to the right of the bullet. If that character isn't a marker, the
macro will insert the autotext between the bullet and the (former) first
character.