How to Delete multiple continuous pages in MS Word using Excel VBA ?

ajay1111

New Member
Joined
Aug 15, 2022
Messages
17
Office Version
  1. 2016
Platform
  1. Windows
I have a list of pages that I want to delete in MS Word such as Page number : 5 to 10 , 12-16 etc. through Microsoft Excel VBA.
I found a code to delete specific pages through MS Word VBA. How can it be achieved through MS Excel VBA.

VBA Code:
Dim Rng As Range, iPage As Long
iPage = 2
With ActiveDocument
  Set Rng = .GoTo(What:=wdGoToPage, Name:=iPage)
  Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
  Rng.Delete
End With
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Dim myRange As Range
Set myRange = ActiveDocument.Range(Start:=ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=5).Start, _
End:=ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=10).End)
myRange.Delete

Set myRange = ActiveDocument.Range(Start:=ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=12).Start, _
End:=ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=16).End)
myRange.Delete.

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,216,125
Messages
6,128,998
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top