UGLY DELETE PAGE CODE

  • Thread starter FIRSTROUNDKO via OfficeKB.com
  • Start date
F

FIRSTROUNDKO via OfficeKB.com

Hi!

How can i delete the pages 1-3 with better code?

Sub Macro1()

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Bookmarks("\Page").Select
Selection.Delete

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Bookmarks("\Page").Select
Selection.Delete

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Bookmarks("\Page").Select
Selection.Delete

End Sub

Thanks in advance
 
B

Brian

Sub DeletePages()
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = GetObject(, "Word.Application")
Set oDoc = oWrd.ActiveDocument
oDoc.Range(0, 0).Select
With oWrd
.Selection.ExtendMode = True
.Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=4 '!
.Selection.Delete
End With
End Sub

Hope it helps
 
F

FIRSTROUNDKO via OfficeKB.com

Thanks Brian
Sub DeletePages()
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = GetObject(, "Word.Application")
Set oDoc = oWrd.ActiveDocument
oDoc.Range(0, 0).Select
With oWrd
.Selection.ExtendMode = True
.Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=4 '!
.Selection.Delete
End With
End Sub

Hope it helps
[quoted text clipped - 17 lines]
Thanks in advance
 

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.

Ask a Question

Top