Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 14 Aug 2008 12:47:04 -0700,    group: microsoft.public.word.vba.general        back       


delete a page   
I amy trying to write a macro that will delete pages 7,9,10 and 12 of a 18 
page document. I can see how to get to a page, but then I cannot figure out 
the commands to delete specific pages.
date: Thu, 14 Aug 2008 12:47:04 -0700   author:   Flash Gordon Flash

Re: delete a page   
Hi Flash,

Here's one way:
Sub DeletePages()
Dim i As Integer
Dim MyRange As Range
Set MyRange = ActiveDocument.Range(0, 0)
For i = ActiveDocument.Range.Information(wdActiveEndPageNumber) To 1 Step -1
If i = 7 Or i = 7 Or i = 9 Or i = 10 Or i = 12 Then
    Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
    Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
    MyRange.Delete
  End If
Next
End Sub

-- 
Cheers
macropod
[MVP - Microsoft Word]


"Flash Gordon" <Flash Gordon@discussions.microsoft.com> wrote in message news:B56BF3D2-3644-4C05-A820-B1B0BD41A44E@microsoft.com...
>I amy trying to write a macro that will delete pages 7,9,10 and 12 of a 18 
> page document. I can see how to get to a page, but then I cannot figure out 
> the commands to delete specific pages.
date: Fri, 15 Aug 2008 07:36:20 +1000   author:   macropod lid

RE: delete a page   
I think you'll find that Word's definition of a "page" is very fluid and can 
be influenced by things like the specified printer and finer details of style 
definitions, amongst others. In fact, you will note that the Page object is 
not a child of the Document object. Instead, it is only related to the 
Document object by way of the Pane object through the Window object. In 
addition, there is no Delete method for the Page object. This alone should 
indicate that the concept of "deleting a page" may not be as simple as one 
might think.

However, here are some tips that may assist you in your efforts:

Consider deleting the last page first. The reason for this should be fairly 
obvious: as soon as you delete, for example, page 7, page 9 is now page 8, 
page 10 is page 9, and so on. Deleting the last page first avoids this 
problem.

You may be tempted to select the page you want to delete and then delete the 
selection. With only four pages to delete, this would probably be acceptable. 
However, it's better practice to define a Range object for the page and then 
delete the specified range. This will be quicker and won't cause the screen 
to jump around.

In addition, due to the fact that the Page object has no Delete method and 
no Range property , you will not be able to work with the Page object 
directly. Instead, you will have to use the range of the hidden "\page" 
bookmark for each page, as shown in the sample code that macropod has 
provided (which actually shows practical application of all the 
recommendation outlined above).

Finally, if at all possible, I would look for a way to explicitly define the 
content to be deleted - possibly though the use of a series of bookmarks. 
This will help to avoid the problems associated with the imprecision inherent 
in Word's definition of a page.

BTW, I would be tempted to use a 'Select Case' statement in place of 
macropod's 'If' statement, as follows:

<snip>
Select Case i
Case 7, 9, 10, 12
    Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
    Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
    MyRange.Delete
Case Else
    ' Do nothing
End Select
<snip>

However, this is just a matter of personal preference in that I find this 
construction to be a bit more "descriptive" and simpler to understand, debug 
and maintain. A series of 'Or' comparisons, while perfectly acceptable to the 
machine, can be a bit more difficult for "wetware" to interpret. (And 'Case' 
statements just look prettier IMHO... <g>)

-- 
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all 
follow-ups to the newsgroup.


"Flash Gordon" wrote:

> I amy trying to write a macro that will delete pages 7,9,10 and 12 of a 18 
> page document. I can see how to get to a page, but then I cannot figure out 
> the commands to delete specific pages.
date: Thu, 14 Aug 2008 15:12:02 -0700   author:   Gordon Bentley-Mix gordon(dot)bentleymix(at)gmail(dot)com

RE: delete a page   
Your definition of page was very en lighting. My objective is to to wind up 
with a sub-document that only has specific pages cut/extracted  from a master 
document--using my past example. Perhaps it would be easier to copy or 
"merge" specific pages into a blank document. Maybe I am asking the wrong 
question about deleting specific pages. What is the best way to accomplish my 
objective. Thanks for your help.
-- 
Al Gordon


"Gordon Bentley-Mix" wrote:

> I think you'll find that Word's definition of a "page" is very fluid and can 
> be influenced by things like the specified printer and finer details of style 
> definitions, amongst others. In fact, you will note that the Page object is 
> not a child of the Document object. Instead, it is only related to the 
> Document object by way of the Pane object through the Window object. In 
> addition, there is no Delete method for the Page object. This alone should 
> indicate that the concept of "deleting a page" may not be as simple as one 
> might think.
> 
> However, here are some tips that may assist you in your efforts:
> 
> Consider deleting the last page first. The reason for this should be fairly 
> obvious: as soon as you delete, for example, page 7, page 9 is now page 8, 
> page 10 is page 9, and so on. Deleting the last page first avoids this 
> problem.
> 
> You may be tempted to select the page you want to delete and then delete the 
> selection. With only four pages to delete, this would probably be acceptable. 
> However, it's better practice to define a Range object for the page and then 
> delete the specified range. This will be quicker and won't cause the screen 
> to jump around.
> 
> In addition, due to the fact that the Page object has no Delete method and 
> no Range property , you will not be able to work with the Page object 
> directly. Instead, you will have to use the range of the hidden "\page" 
> bookmark for each page, as shown in the sample code that macropod has 
> provided (which actually shows practical application of all the 
> recommendation outlined above).
> 
> Finally, if at all possible, I would look for a way to explicitly define the 
> content to be deleted - possibly though the use of a series of bookmarks. 
> This will help to avoid the problems associated with the imprecision inherent 
> in Word's definition of a page.
> 
> BTW, I would be tempted to use a 'Select Case' statement in place of 
> macropod's 'If' statement, as follows:
> 
> <snip>
> Select Case i
> Case 7, 9, 10, 12
>     Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
>     Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
>     MyRange.Delete
> Case Else
>     ' Do nothing
> End Select
> <snip>
> 
> However, this is just a matter of personal preference in that I find this 
> construction to be a bit more "descriptive" and simpler to understand, debug 
> and maintain. A series of 'Or' comparisons, while perfectly acceptable to the 
> machine, can be a bit more difficult for "wetware" to interpret. (And 'Case' 
> statements just look prettier IMHO... <g>)
> 
> -- 
> Cheers!
> Gordon
> 
> Uninvited email contact will be marked as SPAM and ignored. Please post all 
> follow-ups to the newsgroup.
> 
> 
> "Flash Gordon" wrote:
> 
> > I amy trying to write a macro that will delete pages 7,9,10 and 12 of a 18 
> > page document. I can see how to get to a page, but then I cannot figure out 
> > the commands to delete specific pages.
date: Fri, 15 Aug 2008 03:55:02 -0700   author:   Flash

Re: delete a page   
Hi Flash,

Making a copy of a document and deleting the unwanted pages from it to make a sub-set, is probably as easy as, if not easier than, 
copying the 'wanted' pages to a new file. Apart from not making the copy for you - which you didn't ask for - the code I posted 
takes the first course.

-- 
Cheers
macropod
[MVP - Microsoft Word]


"Flash"  wrote in message news:E3568DE7-B19F-4E6C-BF3E-99A512F9E82C@microsoft.com...
> Your definition of page was very en lighting. My objective is to to wind up
> with a sub-document that only has specific pages cut/extracted  from a master
> document--using my past example. Perhaps it would be easier to copy or
> "merge" specific pages into a blank document. Maybe I am asking the wrong
> question about deleting specific pages. What is the best way to accomplish my
> objective. Thanks for your help.
> -- 
> Al Gordon
>
>
> "Gordon Bentley-Mix" wrote:
>
>> I think you'll find that Word's definition of a "page" is very fluid and can
>> be influenced by things like the specified printer and finer details of style
>> definitions, amongst others. In fact, you will note that the Page object is
>> not a child of the Document object. Instead, it is only related to the
>> Document object by way of the Pane object through the Window object. In
>> addition, there is no Delete method for the Page object. This alone should
>> indicate that the concept of "deleting a page" may not be as simple as one
>> might think.
>>
>> However, here are some tips that may assist you in your efforts:
>>
>> Consider deleting the last page first. The reason for this should be fairly
>> obvious: as soon as you delete, for example, page 7, page 9 is now page 8,
>> page 10 is page 9, and so on. Deleting the last page first avoids this
>> problem.
>>
>> You may be tempted to select the page you want to delete and then delete the
>> selection. With only four pages to delete, this would probably be acceptable.
>> However, it's better practice to define a Range object for the page and then
>> delete the specified range. This will be quicker and won't cause the screen
>> to jump around.
>>
>> In addition, due to the fact that the Page object has no Delete method and
>> no Range property , you will not be able to work with the Page object
>> directly. Instead, you will have to use the range of the hidden "\page"
>> bookmark for each page, as shown in the sample code that macropod has
>> provided (which actually shows practical application of all the
>> recommendation outlined above).
>>
>> Finally, if at all possible, I would look for a way to explicitly define the
>> content to be deleted - possibly though the use of a series of bookmarks.
>> This will help to avoid the problems associated with the imprecision inherent
>> in Word's definition of a page.
>>
>> BTW, I would be tempted to use a 'Select Case' statement in place of
>> macropod's 'If' statement, as follows:
>>
>> <snip>
>> Select Case i
>> Case 7, 9, 10, 12
>>     Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
>>     Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
>>     MyRange.Delete
>> Case Else
>>     ' Do nothing
>> End Select
>> <snip>
>>
>> However, this is just a matter of personal preference in that I find this
>> construction to be a bit more "descriptive" and simpler to understand, debug
>> and maintain. A series of 'Or' comparisons, while perfectly acceptable to the
>> machine, can be a bit more difficult for "wetware" to interpret. (And 'Case'
>> statements just look prettier IMHO... <g>)
>>
>> -- 
>> Cheers!
>> Gordon
>>
>> Uninvited email contact will be marked as SPAM and ignored. Please post all
>> follow-ups to the newsgroup.
>>
>>
>> "Flash Gordon" wrote:
>>
>> > I amy trying to write a macro that will delete pages 7,9,10 and 12 of a 18
>> > page document. I can see how to get to a page, but then I cannot figure out
>> > the commands to delete specific pages.
date: Fri, 15 Aug 2008 21:41:04 +1000   author:   macropod lid

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us