Excel精英培训网

 找回密码
 注册
查看: 1256|回复: 0

vba判断word文字颜色是否为蓝色的两种代码

[复制链接]
发表于 2012-4-29 18:11 | 显示全部楼层 |阅读模式
①第一种代码
  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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-4 10:20 , Processed in 0.241506 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表