Exact style name

D

Dinko Deranja

Let's suppose that style which is displayed in Word's combobox is:
"Normal + 16pt, Bold, Centered"

When i try to display the style using: Msgbox(myRange.Style) it displays
only "Normal" without the rest of formatting that Word displays in its combo
box.

How can I find out the exact styling that is being used on a particular
range object?
 
D

Doug Robbins - Word MVP

Hi Dinko,

Use:

Dim Alignment As String
Dim Bold As String
If Selection.ParagraphFormat.Alignment = 1 Then Alignment = ", Centered"
If Selection.Font.Bold = -1 Then Bold = ", Bold"
MsgBox Selection.Style & ", " & Selection.Font.Name & ", " &
Selection.Font.Size & Bold & Alignment


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Dinko Deranja

Thanks Doug!

But this solves the problem only partially. What if the Normal style is
changed to use the "Centered" alignment by default? Then, only "Normal"
would be written in the Word's combo box, wouldn't it?

What I really need is to reliably find out whether the selected range
differs from what is defined in the "Normal" style or not.
 
D

Doug Robbins - Word MVP

Hi Dinko

You would need to use:

Dim Alignment As String
If Selection.ParagraphFormat.Alignment <>
ActiveDocument.Styles("Normal").ParagraphFormat.Alignment Then
If Selection.ParagraphFormat.Alignment = 1 Then
Alignment = ", Centered"
ElseIf Selection.ParagraphFormat.Alignment = 2 Then
Alignment = ", Right"
Else
Alignment = ", Justified"
End If
End If


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
K

Klaus Linke

Hi Dinko,

I think there is some misunderstading:
"Normal + 16pt, Bold, Centered" is not a style. The style is Normal, and
formatting "16 pt, Bold, Centered" has been manually applied on top of the
selected text.

You can get the full text directly from the control:
? CommandBars.FindControl(Id:=1732).Text

Regards,
Klaus
 
D

Dinko Deranja

Klaus Linke said:
Hi Dinko,

I think there is some misunderstading:
"Normal + 16pt, Bold, Centered" is not a style. The style is Normal, and
formatting "16 pt, Bold, Centered" has been manually applied on top of the
selected text.

Of course.
You can get the full text directly from the control:
? CommandBars.FindControl(Id:=1732).Text

I will try tomorrow if it is possible to obtain this value from VB
application which calls Word ih hidden state.
 
K

Klaus Linke

Hi Dinko,

I was fooled by the thread's header, and didn't read the messages
carefully. Sorry!

"Keep track of formatting" was only introduced with Word2002, I think.

I'd be very pleasantly surprised if there is a VBA way to get at the manual
formatting description.

With many new features, VBA support is bad, broken, or non-existant.
The formatting "pseudo styles" are just one example. Multiple selections,
the task panes, and the Office clipboard are some others.
Things that used to work get broken.
No idea whether automation support isn't a priority any more, or whether
Microsoft currently concentrates all ressources on .NET?

One chance to get at new functionality that is in the user interface
sometimes are the built-in commands (like
"WordBasic.SelectSimilarFormatting"), but I can't think of any way to get
at the description except Doug's method to re-construct something like it
yourself, or the one I have given (which is probably worthless for your
automation program).

:-(
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top