Results 1 to 11 of 11

Thread: How can I count the number of words for a specific colorindex

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    Paul,

    That got things closer but then the count was off for "automatic color" text in the sample above. This worked though for both cases. Thanks

    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long, Rng As Range
    Set Rng = Selection.Range
    With ActiveDocument.Range
      .Font.Hidden = True
        With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "<*>" 'Revised GKM
        .Font.Color = Rng.Characters.First.Font.Color
        .Replacement.Text = "~*~ " 'Revised GKM
        .Replacement.Font.Hidden = False
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchWildcards = True 'Added GKM
        .MatchCase = False
        .Execute Replace:=wdReplaceAll
      End With
      i = .ComputeStatistics(wdStatisticWords)
      Undo 2
    End With
    Rng.Select
    Application.ScreenUpdating = True
    MsgBox "There are " & i & " words in the selected colour.", vbInformation
    End Sub
    Last edited by macropod; 03-18-2018 at 02:19 PM. Reason: Fixed code tagging
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •