Word style changes after Font property accessed

A

Alfontz

I've got an issue here and don't see any other postings about it.

I’m building a list of styles from the ActiveDocument but when I access the
Font property of the style (style.Font). The Heading styles in the document
get changed. It actually happens when the loop hits the ‘Article / Section’
style and then all Heading styles are modified.

I need a workaround to get the list of styles and font info for the current
document.
Here’s how to reproduce:

Create a new blank doc. Add a line of text and format with Heading 1.
Open the VB editor (Alt-F11) and paste in the following code and run it.
Notice the line of text AND the Heading styles are changed!!

Thanks,
Alfontz

Sub foo()
Dim i As Integer
Dim strFontName As String
Dim s As style

For i = 1 To ThisDocument.Styles.Count
Set s = ThisDocument.Styles.Item(i)
strFontName = s.Font.Name ' This line will change the styles????
Next i
End Sub

even simpler code does the same thing:

Sub foo2()
Dim strFontName As String
Dim s As style
Set s = ThisDocument.Styles.Item('Article / Section')
strFontName = s.Font.Name ' This line will change the styles????
End Sub
 

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