Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 04-30-2017, 01:37 PM
bnyamin bnyamin is offline find colors then .... Windows 7 64bit find colors then .... Office 2010 64bit
Advanced Beginner
find colors then ....
 
Join Date: Oct 2014
Posts: 36
bnyamin is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Paul,

I like your function! As you know, your use of "Find.Found" shivers my timbers so I try to avoid it. Tinkering with your code, I did notice that it can hiccup if there are color adjacent to each other. This can probably be refined but seems to work:

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrClr As String
Dim i As Long, oRng As Range, oRngCompare As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Format = True
    .Wrap = wdFindContinue
    .Font.ColorIndex = wdAuto
    .Replacement.Font.Hidden = True
    .Execute Replace:=wdReplaceAll
    .ClearFormatting
    .Wrap = wdFindStop
    .Font.Hidden = False
    Do While .Execute
      With oRng
        StrClr = GetClr(.Characters.First.Font.Color, .Characters.First.Font.ColorIndex)
        If .Font.ColorIndex <> wdAuto Then
          Set oRngCompare = oRng.Duplicate
          With oRngCompare
            .Collapse wdCollapseStart
            .Text = "<" & StrClr & ">"
            .Font.ColorIndex = wdAuto
          End With
          .Start = oRngCompare.End
          Set oRngCompare = .Duplicate
          oRngCompare.Collapse wdCollapseStart
          If Asc(.Characters.Last) = 13 Then
            Do While .Characters.Last.Font.Color = .Characters.Last.Next.Font.Color
              .End = .End + 1
            Loop
          End If
          With .Duplicate
            For i = 1 To .Characters.Count
            If .Characters(i).Font.Color = .Characters(1).Font.Color Then
              oRngCompare.End = oRngCompare.End + 1
              oRngCompare.Select
            Else
              Exit For
            End If
            Next i
          End With
          .End = oRngCompare.End
          .Select
          .Collapse wdCollapseEnd
        .Text = "</" & StrClr & ">"
        .Font.ColorIndex = wdAuto
        End If
        .Collapse wdCollapseEnd
        If .End >= ActiveDocument.Range.End - 1 Then Exit Do
      End With
    Loop
  End With
  ActiveDocument.Range.Font.Hidden = False
  Application.ScreenUpdating = True
End Sub

I would like to thank all friends
After running the code ...
Error message comes ...»»»
Attached Files
File Type: zip 2.zip (198.2 KB, 8 views)
File Type: docm run vb (3).docm (23.6 KB, 8 views)

Last edited by bnyamin; 04-30-2017 at 07:06 PM.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
find colors then .... Customization of colors marif300 Project 3 02-23-2015 07:48 AM
find colors then .... Bar colors ketanco Project 1 03-30-2013 08:24 AM
find colors then .... Unable to change font colors from theme colors choy Word 3 08-01-2012 09:12 PM
find colors then .... Counting Colors g48dd Excel 2 03-13-2011 09:28 PM
Hyperlink colors pamm13 Word 2 02-18-2011 08:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft