Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

UGLY DELETE PAGE CODE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FIRSTROUNDKO - 17 Jul 2007 16:01 GMT
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
Brian - 19 Jul 2007 12:34 GMT
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
Signature

Brian McCaffery

> Hi!
>
[quoted text clipped - 17 lines]
>
> Thanks in advance
FIRSTROUNDKO - 19 Jul 2007 15:26 GMT
Thanks Brian

>Sub DeletePages()
>Dim oWrd As Word.Application
[quoted text clipped - 18 lines]
>>
>> Thanks in advance
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.