PDA

View Full Version : Deleting sections /paragraphs in word doc



Asi
02-19-2009, 02:06 AM
Hi

I am opening a word doc via an excel macro and one of the things I want to do to this doc is - delete one or more sections that I know in advance which ones are they.

My question is: what is the best way to acheive that ? is it with Bookmarks ? sections ? paragraphs ?
A code sample would be of great help here.

Thanks
Asi

fumei
02-19-2009, 10:30 AM
Please clarify what you mean by "section".

If it is a "section" that is in your mind - "I mean from PointA to PointB" - then that is a little difficult because you have to find a way to tell Word what those points are. Word can not read minds.

If it is a Section, a real Section - defined by Section breaks - then Word does know what those are. In which case, deleting them is easy.

ActiveDocument.Sections(3).Range.Delete
Deletes Section(3).


However...that will have complications if you have any headers and footers, as they are child objects of the Section.

If you know in advance, and you have already bookmarked the area, then certainly, that would be very handy.

ActiveDocument.Bookmarks("ThisChunk").Range.Delete

Asi
02-22-2009, 04:49 AM
thanks. Bookmarks will do the work