PDA

View Full Version : How to delete shapes and blank pages on document



mazatlan
07-09-2010, 11:28 AM
Hi:
I have a word template with one page and use a macro to add graphics and table to it. The problem is everytime I run the macro the document adds more pages. I need help with a loop to delete all the pages and shapes from my document leaving only the first page(template) to be reused again. I basically want to delete page 2 to last page everytime my macro runs so I can start with a fresh copy. I do have a loop to delete my shapes but the blank pages don't get deleted. Here is the loop I am using:
My file name is wordDoc.
with wordDoc.InlineShapes
Do While .Count > 0
.Item(1).Delete
Loop
End With

I don't know how to use the loop above to delete pages. Thanks for any help

Tinbendr
07-11-2010, 06:52 AM
I can't help but think that whole problem here, started with the original macro.


The problem is everytime I run the macro the document adds more pages.Here is the real problem.


I basically want to delete page 2 to last page everytime my macro runs so I can start with a fresh copy.If your file is saved as a TEMPLATE (*.dotm), then you should start out every file with a fresh copy. When you save a file as a template, the document is created as a COPY of the template. Thus the template never changes.

So, why don't you post the code you have so far (use the VBA tags ), and let's see if we can refine it so that it doesn't add pages.

fumei
07-12-2010, 09:26 AM
Absolutely. Properly done, a template always gives a fresh copy -as that is precisely the point of using templates. Properly done, macros executed during the cloning of a new document will NEVER change the original template file.