Delete first page

L

LEU

I am replacing the first page of my old document with the first page of our
new template. My macro below is not working right. It deletes the old footers
and the old first page but it inserts all the pages of the new template. I
tried putting a bookmark at the end of the first page of the new template and
in my range put in the bookmark so it read as follows but that did not work.
I tried the bookmark on both sides of the page break with no success. What am
I doing wrong?

objRange.InsertFile FileName:="C:\Procedure Master2.dot", _
Range:="bkpg1", ConfirmConversions:=False, Link:=False, _
Attachment:=False


The other problem I’m having is on some of the computers here at work when I
try to run this macro I get the following run-time error: ‘5941’ The
requested member of the collection does not exist. When I run debug it on the
following line:

Selection.Bookmarks("\Page").Range.Delete

When I run this macro on my computer here at work or at home I never get
this error.



Here is my macro:

Dim objSection As Section
Dim objRange As Range
Dim objHeaderFooter As HeaderFooter

' Delete all footers from each section

For Each objSection In ActiveDocument.Sections
For Each objHeaderFooter In objSection.Footers
objHeaderFooter.Range.Delete
Next objHeaderFooter
Next objSection

' Create a range for the start of the document

Selection.Bookmarks("\Page").Range.Delete
Set objRange = ActiveDocument.Range
objRange.End = objRange.Start
objRange.InsertFile FileName:="C:\Master2.dot", _
Range:="", ConfirmConversions:=False, Link:=False, _
Attachment:=False
 
D

Doug Robbins - Word MVP

I would suggest that you try doing the reverse - create a new document from
your new template and insert into it the part of your old document that you
want to use.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

Fuzzhead

Hi Doug,

My old documents are WordPerfect documents. I have my macro that cleans up
the document after it is converted. I was trying to just insert the first
page from the template because after my macro runs the only thing missing
from the converted document is the first page of the new template.

LEU
 
D

Doug Robbins - Word MVP

Use

Dim target As Document, source As Document
Dim pageone As Range
Set target = ActiveDocument
Set source = Documents.Add("yournewtemplate")
Set pageone = source.Bookmarks("\page").Range
target.Range.InsertBefore pageone
source.Close wdDoNotSaveChanges


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

Hi Doug,

I tried your macro but it did not work correctly. It inserted the first page
but it did not bring in the header, bookmarks or tables. The only thing that
came in was the plain text.

LEU
 
D

Doug Robbins - Word MVP

That is because Headers and Footers are Section properties, not Page
properties.

Why don't you just create a new template that just contains the first page
and go back to your original method, using that template.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

That was to simple. It worked great. I guess sometimes you just can't see the
trees through the forest.

Thanks again for you help.

LEU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top