如何遍历Word文档中的所有字体设置
现在有一篇文档,五花八门地设置了各种字体、字号、颜色之类的,现在,我想按照文档的顺序,把这篇文档里面用到的字体、字号、颜色用MsgBox显示出来,这该如何实现?
[解决办法]
Sub aa() '这个宏可以列出文档中所有的字体名称
Dim fontname(1 To 100) As String
Dim i As Integer, j As Integer, n As Integer, k As Integer
Selection.WholeStory
k = Selection.End
ActiveDocument.Range(Start:=0, End:=1).Select
fontname(1) = Selection.Font.Name
n = 2
For i = 0 To k - 1
ActiveDocument.Range(Start:=i, End:=i + 1).Select
For j = 1 To n - 1
If fontname(j) = Selection.Font.Name Then
Exit For
End If
Next j
If j = n Then
fontname(n) = Selection.Font.Name
n = n + 1
End If
Next i
For i = 1 To 100
If fontname(i) = "" Then
Exit For
Else
Debug.Print fontname(i)
End If
Next i
End Sub