Retrieve Text Under Heading

M

Murp

I have a film script in which all the scenes are formatted as Heading 2. I
was wondering if it was possible to use VBA to create a new Word document
that compiles all the text for a number of scenes, e.g. if I want scenes 1, 4
and 7, VBA can find the headings in the document and paste all the associated
text for these headings into a new document?

I must apologise for my vague question - I know VBA from Access, but I have
no idea with Word.
 
J

Jezebel

Yes, this is fairly straightforward. I'd suggest something along these
lines ---

1. Set up a UserForm with a listbox for selecting the scenes you want.

2. Populate the listbox by iterating the paragraphs of the document looking
for paragraphs of style 2 (or with Outline level 2). Each time you find one,
add the paragraph text to the list box, and also record (perhaps in a
second, hidden, column in the listbox) the start of the paragraph range
(myPar.Range.Start).

3. For each section the user selects, create a range object, starting with
that heading's Start point, up to the next heading's start minus 1---

set pRange = MyDoc.Range(Start:=MyList.List(pIndex,2),
End:=MyList.List(pIndex + 1,2)-1)

4. Copy that range into a new document.
 

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