Select Multiple Sections

A

Annie

Hello All, A complex form document in Word 2003 is split into sections (so
hyperlinks can work). Only specific sections need to be copied. I've tried
some of the methods posted in this forum, but can success is limited to one
section.
How could this be edited to select all sections 2-5? I thought the hyphen
would work, but it does not. Thank you so much for any help. Annie

ActiveDocument.Sections(2-5).Range.Select
Selection.End = Selection.End
Selection.Copy
 
L

Lene Fredborg

If you only want to copy the sections, you do not need to select them first
when you use the Range object. The following will copy sections 2-5:

With ActiveDocument
.Range(.Sections(2).Range.Start, .Sections(5).Range.End).Copy
End With

If you for some reason want to select the sections too:

With ActiveDocument
.Range(.Sections(2).Range.Start, .Sections(5).Range.End).Select
Selection.Copy
End With

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
A

Annie

Hi Lene, If I had to add more sections, is there a logical way to select for
copy sections 2 to the end except for the last section? I'm just curious
about saving some editing time. Cheers, Annie
 
L

Lene Fredborg

Yes, you can calculate the number of the second last section by subtracting 1
from the total number of sections.

If you replace:
..Sections(5)
with
..Sections(.Sections.Count - 1)
it should work - the full code line will then look like this:

..Range(.Sections(2).Range.Start, .Sections(.Sections.Count -
1).Range.End).Select
(replace ".Select" with ".Copy" if this is what you want).

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
A

Annie

Thank you Lene. I am saving all these snippets as VB Help usually does not
help very much, and often code is reused. I am also visiting your website!
Annie
 

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