From: Fumei2 via OfficeKB.com on
Ooops, I forgot your 8th word thing.

Dim oSection As Section
Dim r As Range
Dim ParaRange As Range
Dim TempDoc As Document

For Each oSection In ActiveDocument.Sections
Set r = oSection.Range
Set TempDoc = Documents.Add
With TempDoc
.Range = r
Set ParaRange = r.Paragraphs(8).Range
.SaveAs Filename:= ParaRange.Words(ParaRange.Words.Count - 1) & ".
doc"
.Close
End With
Set TempDoc = Nothing
Next

This assumes the the 8th paragraph terminates with a paragraph mark. which is
counted as a "word", thus it is .Words.Count - 1 - to get the last text word
before the paragraph mark.


Gerry
Fumei2 wrote:
>Let's deal with this first:
>
>"Also, is it possible to pull only a portion of the paragraph, i.e.
>only the last word??"
>
>Yes.
>
>You do not have the variable para declared - a bad thing really - but if it
>is a RANGE, then you can get the last word out.
>
>Dim strLastWord As String
>Dim rngPara as Range
>
>strLastWord = rngPara.Words(rngPara.Words.Count)
>
>Next...
>
>You do NOT have to make a copy and paste operation. You can - again - use a
>Range object (with a Section object).
>
>Dim oSection As Section
>Dim r As Range
>Dim TempDoc As Document
>
>For Each oSection In ActiveDocument.Sections
> Set r = oSection.Range
> Set TempDoc = Documents.Add
> With TempDoc
> .Range = r
> .SaveAs Filename:= "whateverNameYou want"
> .Close
> End With
> Set TempDoc = Nothing
>Next
>
>Gerry
>
>
>>I found the original code through this link:
>>http://support.microsoft.com/?kbid=216201
>[quoted text clipped - 48 lines]
>>Thank you in advance for any help!
>>Saf
>

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201003/1

From: Fumei2 via OfficeKB.com on
Lastly, it should be mentioned that by hard-coding the paragraph number (8),
you had better be using proper styles, and none of those "empty" paragraphs
people use to make space between paragraphs. Each one of those is a real
paragraph and is counted!

Fumei2 wrote:
>Ooops, I forgot your 8th word thing.
>
>Dim oSection As Section
>Dim r As Range
>Dim ParaRange As Range
>Dim TempDoc As Document
>
>For Each oSection In ActiveDocument.Sections
> Set r = oSection.Range
> Set TempDoc = Documents.Add
> With TempDoc
> .Range = r
> Set ParaRange = r.Paragraphs(8).Range
> .SaveAs Filename:= ParaRange.Words(ParaRange.Words.Count - 1) & ".
>doc"
> .Close
> End With
> Set TempDoc = Nothing
>Next
>
>This assumes the the 8th paragraph terminates with a paragraph mark. which is
>counted as a "word", thus it is .Words.Count - 1 - to get the last text word
>before the paragraph mark.
>
>Gerry
>>Let's deal with this first:
>>
>[quoted text clipped - 39 lines]
>>>Thank you in advance for any help!
>>>Saf
>

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201003/1