Delete all pages in project

M

mcwhirt3

Hi,

I have a quasi-program that has a button to reset it in publisher,
basically it opens the main menu userform. I need the vb that does that
to first delete all the pages in the document. I believe I want to use
the pagecount property and set that to a variable, then use that
variable in this line...

noofpages=pagecount
ActiveDocument.Pages(noofpages).Delete

I can't get this to work though. Is there any better way to delete all
of the pages in a document? It must reference the pagecount property
because the project will have a variable amount of pages. Thanks for
any help.
 
E

Ed Bennett

I can't get this to work though. Is there any better way to delete all
of the pages in a document?

You are not allowed to delete all of the pages in the document.

In addition, the code you posted should delete the LAST page in the
publication.

You want something like

Dim i As Integer
For i = NoOfPages to 2
ActiveDocument.Pages(i).Delete
Next

This will leave page 1 remaining.
 
M

mcwhirt3

Hi Ed,

Thanks for your help. I can;t get it o work..the code is

Private Sub CommandButton9_Click()

noofpages = PageCount
Dim i As Integer
For i = noofpages To 2
ActiveDocument.Pages(i).Delete
Next

End Sub

Any idea why?
 
M

mcwhirt3

P.S.

I get a supscript out of range error when running that code. Thanks
again Ed!
 

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