[求助]急求VBA在word文件中查找字符串的代码
求word的宏,可以查询字体颜色不是黑色的字符串,还有字体不是宋体的字符串,请高手指教,感激不尽! <br/> <p><font face="Verdana">Sub Macro1()<br/> If Selection.Font.Bold = True Then<br/> MsgBox "字体是粗体"<br/> Else<br/> MsgBox "非粗体"<br/> End If<br/> If Selection.Font.Name = "宋体" Then<br/> MsgBox "字体是宋体"<br/> Else<br/> MsgBox "非宋体"<br/> End If<br/>End Sub<br/></font></p><p><font face="Verdana">选定一段文字后,运行此宏即可。</p></font> <p>非常感谢管理员的回复,这个问题同事已经帮忙解决了,贴一下他的代码:</p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">Option Explicit</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">Sub aa()<br/>Dim nowpos As Integer<br/>Dim nowrge As Range<br/>Dim endpos As Long<br/>Dim findrge As Range<br/>Dim rgn As Range</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana"></font> </p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">Set findrge = Selection.Range<br/>nowpos = findrge.Characters(1).End<br/>endpos = ActiveDocument.Content.End<br/>findrge.SetRange Start:=nowpos, End:=endpos</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">'findrge.Select</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">For Each rgn In findrge.Characters<br/> With rgn.Font<br/> If .Name <> "MS Pゴシック" Or .Color <> wdColorAutomatic Then<br/> rgn.Select<br/> Exit For<br/> End If<br/> End With<br/>Next</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">End Sub</font></p> <p>原来是要对整个区域里一个一个字符进行判断呀.</p>
<p> </p>
<p>我只判断了所选的字符的相关属性,不是一个一个字符判断的.</p>
页:
[1]