Hi Paulo,
I have multiple objects selected in a document, when i try to work with
the Selection (Selection.Text) object it is placed in the last selected
item in the document. What can i do to place it in the first position
and than iterate through the multiple elements?
You could do a lot of difficult and tedious programming.
As far as I know know, coding for the discontiguous selection
by MS was never finished.
However, if you really want to have it, and if all
of the text in the selection is formatted the same way:
Remember the formatting of the selection.
Check for a formatting, not used otherwise in the doc.
Apply this formatting to the selection.
All parts of the discontiguous selection
are now formatted in a way, unique to the doc.
Search for this formatting, using the range-object.
Insert the text you like, search again.
Having finished, restore the original formatting.
Plus lots of complications.
Yu may even create on array of ranges,
defined by the formatting.
Nothing but a workaround, of course,
but some people enjoy things like that.
Here is an example for counting, how many parts
this kind of selection has:
Function NumberOfSelections() As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Selection.Font.Color = wdColorRed
With rDcm.Find
.Font.Color = wdColorRed
' assumed that there is no red text
.Format = True
While .Execute
NumberOfSelections = NumberOfSelections + 1
Wend
End With
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.Color = wdColorRed
.Format = True
While .Execute
rDcm.Font.Color = wdColorAutomatic ' assumed
rDcm.Collapse direction:=wdCollapseEnd
Wend
End With
End Function
Sub test9001()
MsgBox NumberOfSelections
End Sub
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"