Dim pSection as string
pSection = ActiveDocument.Sections(1).Range
> Read means that only read the section "1.scope of test" content and save
> it into a variable.
[quoted text clipped - 33 lines]
>>>
>>> Thankyou so much for your help before!
Wraithchilde - 09 Nov 2006 15:30 GMT
Jezebel you are awesome. I was trying to figure out how to save a document
with about 500 sections as individual documents and I came across this
answer. Perfect.
john smith was telling us:
john smith nous racontait que :
> Read means that only read the section "1.scope of test" content and
> save it into a variable.
> Just that '1.Scope of Test' section content, no other section will be
> read afterwards.
The easiest way to make this work is to use styles to define the key
paragraphs which are
"1 Scope of Test"
and
"2 Assumptions and Constraints"
in your example.
In my example I assume that they are attributed the Style Heading 1. In the
code, replace "wdStyleHeading1" with whatever style you are using.
Also, I included two tests:
The cursor must be placed in a paragraph with that style (or the macro would
not know where to start) and I check for the end of the document to avoid
error messages or endless loops.
'_______________________________________
Sub SelectText()
Dim parCurrent As Paragraph
Dim rgeFinal As Range
Dim lngParCount As Long
Dim lngParIndex As Long
lngParCount = ActiveDocument.Paragraphs.Count
Set parCurrent = Selection.Paragraphs(1)
lngParIndex = ActiveDocument.Range(0, parCurrent.Range.End) _
.Paragraphs.Count
If parCurrent.Range.Style <> ActiveDocument _
.Styles(wdStyleHeading1) Then
MsgBox "You must place the cursor in a pargraph formatted " _
& "with the style ""Heading 1"".", vbExclamation, _
"Wrong style"
Exit Sub
Else
Set rgeFinal = parCurrent.Range
Do While lngParIndex < lngParCount
Set parCurrent = rgeFinal _
.Paragraphs(rgeFinal.Paragraphs.Count).Next
lngParIndex = lngParIndex + 1
If parCurrent.Range.Style <> ActiveDocument _
.Styles(wdStyleHeading1) Then
rgeFinal.End = parCurrent.Range.End
Else
Exit Do
End If
Loop
End If
MsgBox rgeFinal.Text
End Sub
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
john smith - 07 Sep 2006 21:30 GMT
Hi Jean,
Can we do this automatically by finding that particular title name like "6.
Validation Method" and read the below content of it, store it into
variable. Until it finds "7. Platform Applicable" and stop reading?
Thanks
> john smith was telling us:
> john smith nous racontait que :
[quoted text clipped - 56 lines]
> End Sub
> '_______________________________________
Jean-Guy Marcil - 08 Sep 2006 02:31 GMT
john smith was telling us:
john smith nous racontait que :
> Hi Jean,
>
> Can we do this automatically by finding that particular title name
> like "6. Validation Method" and read the below content of it, store
> it into variable. Until it finds "7. Platform Applicable" and stop
> reading?
Just before the line:
Set parCurrent = Selection.Paragraphs(1)
you could have code that would ask the user what bit of text they want to
use as a starting point. See the on-line help for "InputBox ".
But asking users to type is more likely to create errors. It is much easier
just to ask the user to place the cursor in the paragraph they want to start
from...
Otherwise, what I would do is have a userform with a combobox that would
list all the Level 1 paragraphs. The user would then select the one they
want to use. This way, no typing errors!
Or, if the paragraph to start from is always the same, you could hard code
its text in a constant and do Search in the code just before that line. See
the Find method in the on-line help.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jezebel - 08 Sep 2006 02:45 GMT
Put a section break immediately before each of your headings, then you can
use
a) ActiveDocument.Sections(n).Range to retrieve the entire content of each
section into a variable, and
b) ActiveDocument.Sections(n).Paragraphs(1).Range to retrieve the heading
for each section.
> Hi Jean,
>
[quoted text clipped - 64 lines]
>> End Sub
>> '_______________________________________