Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^m"
.Wrap = wdFindStop
While .Execute
If oRng.Paragraphs(1).Style = "Heading 2" Or _
oRng.Paragraphs(1).Style = "Heading 3" Then
oRng.Delete
Else
oRng.Collapse wdCollapseEnd
End If
Wend
End With
End Sub
This Macro works well most of the time with a few documents I recieve an
error that staes:
Object variable or with block variable not set
Do you know why this is?
I looked at the VBA help, but I did not see any variables that were not
declared.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.