Re: 'For Each' paragraph in selection when selection discontinuous
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 19 Mar 2006 21:28:33 -0500
rafraf,
I don't think there is much available in the way of working with
dicontinuous selections in Word. Here is a rough work around. Do something
funky to the selected text, then process the funky text and while processing
restore the original text.
Sub DoesNotWorkWhenSelectionDiscontinuous()
Dim para As Paragraph
Dim curColor As Long
curColor = Selection.Font.Color
Selection.Font.Color = wdColorBrightGreen
For Each para In ActiveDocument.Paragraphs
If para.Range.Font.Color = wdColorBrightGreen Then
para.Indent
para.Range.Font.Color = curColor
End If
Next para
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
rafraf wrote:
Best way to explain this problem is to demonstrate it. I have only
tried this with Word 2003 SP2.
In a block of three paragraphs, select the first and last paragraph
(do not select the middle paragraph) using ctrl-click. Now execute the
following macro:
Sub WorksWhenSelectionDiscontinuous()
Selection.Paragraphs.Indent
End Sub
As expected, the two paragraphs in your selection indent.
Now try this code with the same selection:
Sub DoesNotWorkWhenSelectionDiscontinuous()
Dim para As Paragraph
For Each para In Selection.Paragraphs
para.Indent
Next para
End Sub
This time, only the last paragraph in the selection indents. Note that
if you select all three paragraphs continuously (i.e. without the ctrl
key) then all paragraphs in the selection will, as expected, indent.
Can anyone explain or provide a workaround*?
*By workaround I mean a way of performing an action on each paragraph
in the selection such that I can do different things based on the
attributes of each paragraph in the (discontinuous) selection.
Cheers all.
.
- References:
- Prev by Date: 'For Each' paragraph in selection when selection discontinuous
- Next by Date: Re: Ignore Case Sensitive
- Previous by thread: 'For Each' paragraph in selection when selection discontinuous
- Next by thread: Re: 'For Each' paragraph in selection when selection discontinuous
- Index(es):
Relevant Pages
|