How can I get the style name for a given range in my word
document? I've tried several things, and the funny thing
is
Debug.print myStyle
will give me the style name (which is all I want,) but
there doesn't seem to be any way to get this information
from the range or style object and assign it to a string.

I'm a little new at VBA, so any help would be appreciated.

Thanks,
L-

Re: MSWord...styles. by Stu

Stu
Tue Jan 06 00:20:35 CST 2004

In VBA it should be available from the Style property of the Selection
object. So, for example, if you positioned the insertion point in the
middle of the third paragraph, then executed the following VBA code, then
the style name would be stored in mStyle.

Dim mStyle
mStyle = selection.style
msgbox "The style of the selected paragraph is " & mStyle

Stu


"Luke" <lcaballero@powereng.com> wrote in message
news:02ae01c3d3dc$08e9ed00$a501280a@phx.gbl...
> How can I get the style name for a given range in my word
> document? I've tried several things, and the funny thing
> is
> Debug.print myStyle
> will give me the style name (which is all I want,) but
> there doesn't seem to be any way to get this information
> from the range or style object and assign it to a string.
>
> I'm a little new at VBA, so any help would be appreciated.
>
> Thanks,
> L-



Re: MSWord...styles. by Helmut

Helmut
Tue Jan 06 04:29:40 CST 2004

Hi Luke,
there must something else be wrong:
Dim S As String
Dim R As Range
Set R = ActiveDocument.Paragraphs(4).Range
S = R.Style
MsgBox S
You get error 91, if the range includes more than one
style. Which is inconsistent compared to returning
other format-properties like format.character, where you
don't get an error, but a constant representing
"various" or "undefined", it is -1 I think, AFAIK.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98



Re: MSWord...styles. by Luke

Luke
Tue Jan 06 10:19:03 CST 2004

Hey thanks, I figured out the problem, I miss read the
documentation. I thought the range property: style
returned a style object, but it returns a variant. Which,
is a string in the case, and is also what I was looking
for.

so eh... my mistake.

Thanks anyway.
L-
>-----Original Message-----
>Hi Luke,
>there must something else be wrong:
>Dim S As String
>Dim R As Range
>Set R = ActiveDocument.Paragraphs(4).Range
>S = R.Style
>MsgBox S
>You get error 91, if the range includes more than one
>style. Which is inconsistent compared to returning
>other format-properties like format.character, where you
>don't get an error, but a constant representing
>"various" or "undefined", it is -1 I think, AFAIK.
>Greetings from Bavaria, Germany
>Helmut Weber
>"red.sys" & chr$(64) & "t-online.de"
>Word 97, W98
>
>
>.
>

Re: MSWord...styles. by Thomas

Thomas
Wed Jan 07 12:44:37 CST 2004

"Luke" <lcaballero@powereng.com> wrote in message
news:001f01c3d470$cd192a30$a301280a@phx.gbl...
> Hey thanks, I figured out the problem, I miss read the
> documentation. I thought the range property: style
> returned a style object, but it returns a variant. Which,
> is a string in the case, and is also what I was looking
> for.
>
> so eh... my mistake.
>
> Thanks anyway.
> L-
> >-----Original Message-----
> >Hi Luke,
> >there must something else be wrong:
> >Dim S As String
> >Dim R As Range
> >Set R = ActiveDocument.Paragraphs(4).Range
> >S = R.Style
> >MsgBox S
> >You get error 91, if the range includes more than one
> >style. Which is inconsistent compared to returning
> >other format-properties like format.character, where you
> >don't get an error, but a constant representing
> >"various" or "undefined", it is -1 I think, AFAIK.
> >Greetings from Bavaria, Germany
> >Helmut Weber
> >"red.sys" & chr$(64) & "t-online.de"
> >Word 97, W98

Luke, that's not quite correct. The Range object's Style property is a
Variant so that you can SET it with either a Style object or a string that's
the name of the style or one of the builtin style constants. When you GET
the Style property, you always get a Style object. The reason you can do S =
R.Style when S is a string is because the default property of the Style
object is NameLocal, which is a string.

-Tom