Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Word Macro remove First Page from doc

Posted on 2007-03-20
8
Medium Priority
?
913 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: 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

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 article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Suggested Courses

636 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