?
Solved

Word Macro remove First Page from doc

Posted on 2007-03-20
8
Medium Priority
?
851 Views
Last Modified: 2012-05-07
Hi,

Can someone tell me how to remove (Ideally the first page) or any page for that maater of a Word Document using word macros ??
0
Comment
Question by:itimes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:Louis01
ID: 18758196
Sorry - I could only find how to delete paragraphs..
Maybe it'l help. Good luck

Sub DeleteSelection()
    Dim intResponse As Integer
   
    intResponse = MsgBox("Are you sure you want to " & _
        "delete the contents of the document?", vbYesNo)
   
    If intResponse = vbYes Then
        ActiveDocument.Paragraphs(1).Range.Select
        Selection.Delete
    End If
End Sub
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 18760400
Pages are a problem for macros. There no Word object corresponding to the visible page. This is because the meaning of a page is volatile, varying with the font, the printer driver and any editing earlier in the document.

Is your first page limited by a hard (manual) page break or next page section break?

If not, this will work, but it takes a noticeable amount of time.

Sub DelPage1()
    Dim r As Range
    Set r = ActiveDocument.Range(0, 0)
    Do Until r.Information(wdActiveEndPageNumber) = 2
        r.MoveEnd wdCharacter, 1
    Loop
    r.MoveEnd wdCharacter, -1
    r.Text = ""
End Sub

0
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 100 total points
ID: 18762315
Hi Graham, you could probably make use of the Predefined Bookmarks to get the active page.

Sub Test1()
sPageToDelete = 4
Selection.GoTo(What:=1, Which:=2, _
Name:=sPageToDelete).Bookmarks("\Page").Range.Delete
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 18762638
Duh! Of course.

itimes,
please ignore my answer & accept Rajesh's

For the sake of understanding the code, we can use built-in constant names instead of the numbers.

Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, _
Name:=sPageToDelete).Bookmarks("\Page").Range.Delete
0
 

Author Comment

by:itimes
ID: 18762647
GrahamSkan:

"Is your first page limited by a hard (manual) page break or next page section break?"

It says "Section Break (Next Page) does thsi help ?? Your code works by teh way but it is a little slow .....

R_Rajesh: This code Failed im afrid !
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
ID: 18762693
Oh yes. A lot easier.

Sub DeleteFirstSection()
    ActiveDocument.Sections(1).Range.Text = ""
End Sub


I don't know why Rajesh's code didn't work for you. I'll test it here.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 18762713
If you have Option Explicit set, you will need to declare the variable. Otherwise Rajesh's code works.

Sub Test1()
    Dim sPageToDelete As Integer
   
    sPageToDelete = 1
    Selection.GoTo(What:=1, Which:=2, _
    Name:=sPageToDelete).Bookmarks("\Page").Range.Delete
End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question