I want to delete section break or page break at current page.but thes vba code does not work.how to modfiy it?
Sub Del_sectionbreakORpagebreak()
Selection.Bookmarks("\page").Range.Select 'select current page
With Selection.Find
.ClearFormatting
.Execute FindText:="^b", Format:=True 'find section break
fnd = .Found
End With
If fnd = True Then
With Selection.Find
.ClearFormatting
.Text = "^b"
.Replacement.Text = " "
.Forward = True
.Execute Replace:=wdReplaceOne
End With
Else
With Selection.Find
.Text = Chr(12)
.Replacement.Text = ""
.Forward = True
.Execute Replace:=wdReplaceOne
End With
End If
End Sub
CodePudding user response:
You can't delete an automatic page break. For other page/section breaks:
Sub Demo()
With Selection.Bookmarks("\page").Range.Characters.Last
If .Text = Chr(12) Then .Text = vbNullString
End With
End Sub
CodePudding user response:
Sub Del_sectionbreak()
Selection.Bookmarks("\page").Range.Select
With Selection.Find
.ClearFormatting
.Execute FindText:="^b", Format:=True
fnd = .Found
End With
If fnd = True Then
Selection.Delete
Else
With Selection.Find
.Text = Chr(12)
.Replacement.Text = vbNullString
.Forward = True
.Execute Replace:=wdReplaceOne
End With
End If
End Sub
the code fuction is delete sectionbreak or pagebreak in current page