VBA determines whether Word text color is blue

Source: Internet
Author: User

① First kind of code

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 + error$ (err), M_title

② the second type of code

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 ' extract found text

. Parent.delete ' Delete found text (blue font)

Loop

End With

If info = "" Then MsgBox "specified color font not found" Else Documents.Add.Content = Info

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.