Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Select Multiple Sections

1,855 views
Skip to first unread message

Annie

unread,
Aug 7, 2007, 4:06:03 PM8/7/07
to
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

Lene Fredborg

unread,
Aug 7, 2007, 4:52:04 PM8/7/07
to
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

Annie

unread,
Aug 7, 2007, 5:04:07 PM8/7/07
to
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

Lene Fredborg

unread,
Aug 7, 2007, 5:14:14 PM8/7/07
to
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).

Annie

unread,
Aug 8, 2007, 6:20:00 PM8/8/07
to
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
0 new messages