Macro to select Section Data

J

Jim K

I need to define a macro in Word 2003 that will select the text is an entire
section without selecting the text on the first line of that section.
Defined a macro that selects section text to the end of the document; need to
stop select at end of that section regardless of how long the section may be.
If anyone has any ideas on how to accomplish this task, please respond.
Thanks.
 
L

Lene Fredborg

You could do as follows (insert the desired section number instead of 1):

ActiveDocument.Sections(1).Range.Select
'Exclude first line
Selection.MoveStart unit:=wdLine, Count:=1

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

Jim K

Thank you very much Lene...this worked great. My entire macro looks as
follows (the (1) is modified to point to the correct section to grab):
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 13/07/2007 by All Users
'
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Microscopic Examination:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
ActiveDocument.Sections(2).Range.Select
'Exclude first line
Selection.MoveStart unit:=wdLine, Count:=1
End Sub

Thanks again,
Jim K
 
J

Jim K

I've since worked on the macro listed below and need additional help with the
following: If this is grabbing data from section 2 in a 3 continuous section
document, I don't want it to grab the section break at the end of section 2.
Is there something I can added to the macro below to end the text selection
just before the next section break and not include that section break?
thanks.
 
R

Russ

Hey Jim,
Try:
If Selection.Characters.Last Like vbFormFeed Then
Selection.End = Selection.End - 1
End If
 

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