View Single Post
 
Old 07-03-2012, 03:36 AM
Charles Kenyon Charles Kenyon is online now Windows Vista Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,165
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

This is the same thing with an Input box to get the page number.
I changed iPage to an Integer because I didn't understand the need for a long variable there.
There may be a type mismatch between the Input Box result and the variable but it seems to work.

Code:
    Dim Rng As Range, iPage As Integer
    On Error Resume Next
    iPage = InputBox("Which page do you want to delete.", "Delete Page")
    With ActiveDocument
      Set Rng = .GoTo(What:=wdGoToPage, Name:=iPage)
      Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
      Rng.Delete
    End With
One other thought: While deleting a page this way will work, "page" is seldom a logical part of a Word document unless you are using manual page breaks. Inserting manual page breaks is generally not a good formatting practice.
Reply With Quote