How to get heading style number font name

C

Coco

I would be grateful if someone could help with this before I go completely
insane. What I want to do is obtain the name of the font used for the number
in a heading style (e.g. "Heading 1").

'With this, I can get the font properties of heading style text

With ActiveDocument.Styles("heading 1")
With .Font
MsgBox (.Name)
'...
End With
End With


'With this, I can get non-font properties of heading style numbers

With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
MsgBox (.StartAt)
'...
End With


'Using the same successful calls and syntax used in the examples above, I
can get font properties of heading style numbers except for the font name. Am
I doing something stupid here is Word known not to reveal what I seek?

With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
With .Font
MsgBox (.Name)
MsgBox (.Italic)
'...
End With
End With

Thanks.
 
H

Helmut Weber

Hi Coco,

hmm...

With
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
MsgBox "[" & .Font.Name & "]"
End With

Works here and now. However, if no font was explicitly
applied to the outline characters, .font.name returns nothing.

By the way, if I format the outline characters as bold
and reset the formatting, the bold stays. ?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Coco

Thanks Helmut but I think that you are referring to text on the page that has
had formatting applied to it. What I am trying to get is the font name set
for the relevant heading style number.
 
H

Helmut Weber

Hi Coco,

if there was a clear and simple method, I'd say,
somebody would have posted a solution.

However, I came about a method "selectnumber",
which works with numbered or bulleted paragraphs,
and seems not to be available from the user interface.

Selection.Paragraphs(1).SelectNumber
MsgBox Selection.Font.Name

So if there is a paragraph formatted as "heading 1",
and "heading 1" includes formatting as e.g.
ListGalleries(wdOutlineNumberGallery)...

you may get the font name, it seems.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Klaus Linke

Selection.Paragraphs(1).SelectNumber
MsgBox Selection.Font.Name

Ingenious! Avoiding the ListGalleries, you could also use

With Selection.Range.ListFormat
MsgBox .ListTemplate.ListLevels(.ListLevelNumber).Font.Name
End With

.... pretty byzantine code though, admittedly, compared to yours.

Regards,
Klaus
 
H

Helmut Weber

Hi Klaus,
Ingenious! Avoiding the ListGalleries, you could also use
With Selection.Range.ListFormat
MsgBox .ListTemplate.ListLevels(.ListLevelNumber).Font.Name
End With

... pretty byzantine code though, admittedly, compared to yours.

I've just looked and looked around and around
and finally came across SelectNumber.
Never heard about that before.

Getting your attention and your consent means something to me.

Have a look at ...de.word
"Suchen/Ersetzen von ...",

where "mso-bidi-font" and "mso-bidi-font-size"
seem to cause trouble.

Schönen Abend noch und gut durchschlafen. ;-)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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