Hello!
I've been having some trouble with the following code:
Code:
Sub AutomaticNumbering()
Dim manum As Field
Dim rgpara As Paragraph
Dim myRange As Range
Dim notag As Range
For Each rgpara In ActiveDocument.Paragraphs
If rgpara.Range.Style = "Text" Then
Set myRange = rgpara.Range
Set notag = myRange.Next(Unit:=wdParagraph, Count:=1)
If notag.Style = "MNS" Then
Else
rgpara.Range.InsertParagraphAfter
myRange.Collapse Direction:=wdCollapseEnd
myRange.Style = "MNS"
Set manum = ActiveDocument.Fields.Add(Range:=myRange, Type:=wdFieldAutoNumLegal, Text:="\Arabic *\e", PreserveFormatting:=True)
End If
End If
Set notag = Nothing
Set myRange = Nothing
Set manum = Nothing
Set rgpara = Nothing
Next rgpara
End Sub
The function works fine, but in the end I get "Run-time error 91 Object Variable or With block variable not set".
The Debug indicates the problem might be related to the following line:
Code:
If notag.Style = "MNS" Then
Does anyone have an idea to help?