如何搜索word文档中的字体
我想用vb处理word文档,下面代码中的那一行“.Name = 黑体”,我打算只用它搜索中文黑体字,但实际上没有达到效果,连中文宋体字都搜到了。是不是字符集的问题,还是其它问题,请高手指点一下。
Private Sub DivideByFontInfo()
'程序功能:获取目前word文档中字号最大的段落,并打印出来
Dim nMaxSize As Integer
Dim colFoundItems As New Collection
'Dim textCurrent As Variant
Dim rngCurrent As Word.Range
Dim intFindCounter As Integer
Dim findtag As Integer
findtag = 0
nMaxSize = 42 '初号字
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
Selection.Find.ClearFormatting
While 1
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
With .Font
.Size = nMaxSize
.Bold = True
.Name = 黑体
'这里的Name属性是针对英文而言的,那么对于中文应该如何表示?
'在这里指定黑体,实际上不起作用,英文就没有黑体
End With
.Execute
Do While .Found = True
findtag = 1
intFindCounter = intFindCounter + 1
colFoundItems.Add Selection.Range, CStr(intFindCounter)
.Execute
Loop
If findtag = 1 Then
GoTo label
Else
nMaxSize = nMaxSize - 1
End If
End With
Wend
label: For Each rngCurrent In colFoundItems
MsgBox "最高标题的内容依次为:" & CStr(rngCurrent.Text)
Next rngCurrent
End Sub