Greg
Wed Mar 29 19:49:35 CST 2006
Jay,
OK. No I am not sure but I will check tomorrow. Since it is working for
you it must be something simple and boneheaded that I did. Thanks.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Jay Freedman wrote:
> Nope. The macro works perfectly here in Word 2000 on Windows XP
> (running in Virtual PC).
>
> Are you sure the style you defined before was a character style, not a
> paragraph style? Or maybe there's something odd about its definition.
>
> Jay
>
> On Wed, 29 Mar 2006 17:45:33 -0500, "Greg Maxey"
> <gmaxey@mvps.oSCARrOMEOgOLF> wrote:
>
>> Jay,
>>
>> Confirming your observations. It works as expected here at home
>> using Word2003. Must be something changed in the Word (let me
>> guess) object module. Correct?
>>
>> Thanks.
>>
>> --
>> Greg Maxey/Word MVP
>> See:
>>
http://gregmaxey.mvps.org/word_tips.htm
>> For some helpful tips using Word.
>>
>> "Jay Freedman" <jay.freedman@verizon.net> wrote in message
>> news:%23ZMxO12UGHA.5496@TK2MSFTNGP11.phx.gbl...
>>> Hi Greg,
>>>
>>> I don't think you're going to want to hear this... I repeated your
>>> experiment, and it applied the character style only to the first
>>> sentence of
>>> each paragraph. There was no unexplainable behavior.
>>>
>>> This is Word 2003 on Windows 2000. If I get time tonight I'll try
>>> it in a couple of other configurations.
>>>
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ:
http://word.mvps.org
>>> Email cannot be acknowledged; please post all follow-ups to the
>>> newsgroup so
>>> all may benefit.
>>>
>>> Greg wrote:
>>>> I was trying to apply a style to the first sentence of each
>>>> paragraph in a document.
>>>>
>>>> For example:
>>>>
>>>> This is paragraph 1 sentence 1. This is paragraph 1 sentence 2.
>>>> Etc. This is paragraph 2 sentence 1. This is paragraph 2 sentence
>>>> 2. Etc.
>>>>
>>>>
>>>> Using this code you will see the message box accurately reports the
>>>> first sentence text, but the .style is applied to the entire
>>>> paragraph.
>>>>
>>>> Sub Scratchmacro1()
>>>> Dim oPar As Paragraph
>>>> Dim oRng As Word.Range
>>>> For Each oPar In ActiveDocument.Range.Paragraphs
>>>> MsgBox oPar.Range.Sentences(1)
>>>> oPar.Range.Sentences(1).Style = "First Sentence"
>>>> Next oPar
>>>> End Sub
>>>>
>>>> However, if I first select the defined range then apply the style
>>>> all is well:
>>>>
>>>> Sub Scratchmacro2()
>>>> Dim oPar As Paragraph
>>>> Dim oRng As Word.Range
>>>> For Each oPar In ActiveDocument.Range.Paragraphs
>>>> oPar.Range.Sentences(1).Select
>>>> Selection.Style = "First Sentence"
>>>> Next oPar
>>>> End Sub
>>>>
>>>> Can anyone explain this behaviour?
>>>>
>>>> Thanks.