List of styles used in header/footer

D

DaveP

Is it possible to programatically get a list of styles used in a header or
footer in a Word document?

It looks like you can get the style used for a selected range, but I don't
want to select the entire header (or footer) because multiple styles might be
used within that selection. And I know you can get a list of styles for an
entire Word document, but can that be broken down into what styles are used
where within a document?

Thanks!
 
H

Helmut Weber

Hi Dave,

like this for the specified header,
though i am not sure whether my error handling
is the state of the art.

I'm thinking also,
speed won't matter much as there
probably aren't hundredths of styles
or paragraphs to be processed.

And this is about paragraph styles only.

Sub Test400945()
Dim lngCnt As Long
Dim colTmp As Collection
Dim prgTmp As Paragraph
Dim rngHdr As Range
Set colTmp = New Collection
Set rngHdr = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
For Each prgTmp In rngHdr.Paragraphs
On Error Resume Next
colTmp.Add prgTmp.Style, Key:=prgTmp.Style
If Err.Number = 457 Then Resume
Next
For lngCnt = 1 To colTmp.Count
Debug.Print colTmp(lngCnt)
Next
End Sub

--
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