Skip to main content

Word VBA delete page selection




Sub Macro_VBA_Delete_Page()



Selection.GoTo wdGoToPage, wdGoToAbsolute, 2

Selection.Bookmarks("\Page").Select

Selection.Delete Unit:=wdCharacter, Count:=1



End Sub

Selection.GoTo wdGoToPage, wdGoToAbsolute, 2
Line above will goto page number "2"

Selection.Bookmarks("\Page").Select
This will select the whole page.

Selection.Delete Unit:=wdCharacter, Count:=1
As the keyword specified "Delete", it will delete the whole page

 
To delete 2 subsequent pages using VBA use code below:

Sub Del_pages()



Dim i

 For i = 1 To 2



Selection.GoTo wdGoToPage, wdGoToAbsolute, 2

Selection.Bookmarks("\Page").Select

 Selection.Delete Unit:=wdCharacter, Count:=1 

Next

End Sub

Code above will delete page 2 and page 3 on the word document

Selection.GoTo wdGoToPage, wdGoToAbsolute, 2

Code above will goto page 2 and once page 2 is deleted, page 3 will become page 2.

Thus on the second loop (of the for loop statement), page 3 will be deleted.


Cheers!!!

=========================


Android Divine Mercy Chaplet Guide  
https://play.google.com/store/apps/details?id=com.dmercyapp 

Comments