macro to delete parts of the document

S

Satya

Hi,

I have a document that may contain only one section and Table of contents.
e.g

TOC
...
...

1 heading1
some text
1.1 heading 1.1
some text
2 heading 2
some text
2.1 heading2.1
some text
2.1.1 heading
some text

Now I want to take input as the number 1 or 1.1 even the heading is fine and
then delete all the contents pertaining to that number, update the TOC.

Thanks in advance
Satya
 
G

George Lee

This is difficult to do. Mostly because Word doesn’t handle lists very well.
The expected calls of listformat and listlevels return only partial
information. It’s unlikely every paragraph will be correctly formatted to
begin with.

In your case, take advantage of the existing TOC and its hyperlinks. You
will need to write a routine to locate the starting point of the section you
want deleted (from the range.start of the hyperlink), and the starting point
of the first section afterwards you don’t want deleted (also from the
range.start of that hyperlink). Define that range based on those two values
and delete it. Depending on the complexity of the TOC this may not be a
trivial task.
 
S

Satya

Thanks George,
could you give me some code examples so that I could proceed further
 

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