您好,欢迎来到 - 67学习网 - http://www.67xuexi.com !

vba判断word文字颜色是否为蓝色

摘要: ①第一种代码On Error GoTo ErrHandleSet myRange = ActiveDocument.Range(Selection.Start, ActiveDocument.Content.End)For Each iChar In myRange.CharactersSelection.MoveRight Unit:=wdCharacter, Count:=1If Selection.Font.ColorIndex = 2 Then MsgBox iCharNextExit SubErrHandle:MsgBox "Error number: " + Str$(Err) + Chr(13) + Error$(Err), 48, m_Title②第二种代码Dim n As Integer, Info As StringWith Selection.Find.Parent.HomeKey wdStory.ClearFormatting.Font.Color = wdColorBlueDo While .Executen =
vba判断word文字颜色是否为蓝色,标签:word教程大全,http://www.67xuexi.com

   ①第一种代码

  On Error GoTo ErrHandle

  Set myRange = ActiveDocument.Range(Selection.Start, ActiveDocument.Content.End)

  For Each iChar In myRange.Characters

  Selection.MoveRight Unit:=wdCharacter, Count:=1

  If Selection.Font.ColorIndex = 2 Then MsgBox iChar

  Next

  Exit Sub

  ErrHandle:

  MsgBox "Error number: " + Str$(Err) + Chr(13) + Error$(Err), 48, m_Title

  ②第二种代码

  Dim n As Integer, Info As String

  With Selection.Find

  .Parent.HomeKey wdStory

  .ClearFormatting

  .Font.Color = wdColorBlue

  Do While .Execute

  n = n + 1

  Info = Info & n & vbTab & .Parent & vbCrLf '提取找到的文本

  .Parent.Delete '删除找到的文本(蓝色字体)

  Loop

  End With

  If Info = "" Then MsgBox "未找到指定颜色字体" Else Documents.Add.Content = Info


Tag:word教程word教程大全办公软件教程 - word教程

《vba判断word文字颜色是否为蓝色》相关文章