quartz was telling us:
quartz nous racontait que :
I accidentally posted this question in another NG, please disregard
the other one.
I need an example function that will copy each line in a Word document
beginning at the first line and ending at the end of paragraph 10.
Each line needs to be separately copied into an array.
Can someone please, please, please post a function to do this? Thanks
so very much in advance.
Here is a "little" something that will work on a document containing at
least 10 paragraphs and no tables/textboxes... You would have to add some
tests/error trapping to make sure there are at least 10 paragraphs, if not,
modify the code to account for that (Especially the Set LineRange =
ActiveDocument.Paragraphs(10).Range line).
'_______________________________________
Dim StartRange As Range
Dim LineRange As Range
Dim LineArray() As String
Dim PageCount As Long
Dim myPage As Page
Dim myRectangle As Rectangle
Dim ParaCount As Long
Dim LineCount As Long
Dim i As Long
Dim j As Long
Dim k As Long
Set StartRange = Selection.Range
Application.ScreenUpdating = False
ParaCount = 1
k = 0
Set LineRange = ActiveDocument.Paragraphs(10).Range
LineRange.Collapse wdCollapseEnd
LineRange.Select
PageCount = Selection.Information(wdActiveEndPageNumber)
Selection.HomeKey wdStory
For i = 1 To PageCount
Set myPage = ActiveWindow.ActivePane.Pages(i)
Set myRectangle = myPage.Rectangles(1)
LineCount = myRectangle.Lines.Count
ReDim Preserve LineArray(k + LineCount)
j = 1
Do While ParaCount < 10
Set LineRange = myRectangle.Lines(j).Range
LineRange.Select
LineArray(k) = LineRange.Text
k = k + 1
j = j + 1
If j > LineCount Then Exit Do
ParaCount = ActiveDocument.Range(0, Selection.End).Paragraphs.Count
Loop
Next
ReDim Preserve LineArray(k - 1)
'Put array in new document
Dim newdoc As Document
Dim DocRange As Range
Dim m As Long
Set newdoc = Documents.Add
Set DocRange = newdoc.Range
For m = 0 To UBound(LineArray)
With DocRange
.InsertAfter LineArray(m)
.Collapse wdCollapseEnd
End With
Next
'Reselect original selection
StartRange.Select
Application.ScreenRefresh
Application.ScreenUpdating = True
'_______________________________________
Since I have just begun playing around with the Pages/Rectangles/Lines
collections, would someone with more experience with these collections
please comment on their usefulness/shortcomings?
TIA
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org