View Single Post
 
Old 10-14-2023, 11:25 PM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Smile Remove empty paragraphs typed before paragraph marks

I've devised this macro to remove empty paragraphs before a footnote, that is: paragraphs previously inserted before the footnote mark in the footnote sector. The macro does its job, but I cannot avoid Runtime Error: 5252. Can someone help? Thanks!

Code:
Sub Remove ()
Set rng = ActiveDocument.StoryRanges(wdFootnotesStory)
With rng.Find
.Text = "^13{2;}"
.MatchWildcards = True
.Execute
End With
If rng.Find.Found = True Then
For n = 1 To 10
rng.MoveUntil rng Like "^#"
rng.Select
rng.Collapse Direction:=wdCollapseEnd
rng.MoveUntil rng Like ".", Extend
    On Error GoTo Quit
rng.Delete , -1 'Runtime Error: 5252
    On Error GoTo 0
Next n
End If
Quit:
End Sub

I modified the macro. The code here below now works perfectly.


Code:
Sub Remove2 () 
Set rng = ActiveDocument.StoryRanges(wdFootnotesStory)
With rng.Find
.Text = "^13{2;}"
.MatchWildcards = True
.Execute
End With
If rng.Find.Found = True Then
rng.MoveUntil rng Like "^#"
rng.Select
For n = 1 To Len(rng) - 1
rng.Collapse Direction:=wdCollapseEnd
rng.MoveUntil rng Like ".", Extend
rng.Delete , -1
Next n
End If
End Sub

Last edited by RobiNew; 10-15-2023 at 06:56 AM. Reason: New code
Reply With Quote