Problem with AddFromRange method

P

p.a.m.swennenhuis

Hi,

I encountered a problem, possibly a bug, in Word 2003 with regards to
the creation of subdocuments.
This function is not always reliable when executed from a macro.
Sometimes it behaves the same as executing the command from within the
Outline view of a document - that is: all selected headers are
promoted to subdocument, as expected - but many times it causes only
the first matching header (and everything it contains) to be promoted
to a subdocument, leaving the rest unchanged.
This can be tested very easily: open a document that has an
outlinestructure, and select the Outline view. Then start the macro
recorder, press Ctrl A to select everything and then click 'Create
Subdocument'. Result: all headers of level 1 are promoted to
subdocuments. Everything ok. Stop the macro recording.
Close the document, without saving changes.
Now open the same document again, and execute the macro that you
recorded earlier. It should do the same, right? But it doesn't: it
creates just one subdocument, from the first header.
The macro looks like this:

Sub CreaSubs()
'
' CreaSubs Macro
' Macro recorded 12/18/2007 by paolo
'
Selection.WholeStory
ActiveDocument.Subdocuments.AddFromRange Range:=Selection.Range
End Sub


The question is: what causes the macro to behave differently from the
commands when executed directly? Is there something 'behind the
screens' that gets executed when clicking 'Create subdocuments'? If
so, can it be mimicked from within the macro environment? I have
developed an add-in that depends greatly on the subdocuments
functionality working properly, so any suggestions would be very
helpful.

Unfortunately I can not attach a document to this message the shows
the erroneous behaviour. On request I can send you one.

Thanks in advance,

Paul Swennenhuis
 

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