Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Word Macro highlighted text

    Hi there

    I've read and searched this forum and tried some of your interesting ideas,
    but I can't find a solution that fits my specific problem.

    For work, I often have to do a character count of all the NON-highlighted text in Microsoft Word.
    I wonder if it's possible to make a Macro for that.

    I was thinking this way: Select All Highlighted Text, Delete Selection, Character Count, Undo Delete.
    (Or maybe there is a more easy way?)

    This helped me a little bit (http://windowssecrets.com/forums/sho...(Word-XP-SR-2)
    but I don't manage to make my Macro work the way I want.

    Thank you very much!

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    That's quite simple:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long, j As Long
    With ActiveDocument.Range
      i = .Characters.Count
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .Highlight = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Do While .Find.Found
        j = j + .Duplicate.Characters.Count
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    MsgBox "This document contains " & i & " characters, of which " & i - j & " are not highlighted."
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. The Following User Says Thank You to macropod For This Useful Post:

    koenbau (2014-12-03)

  4. #3
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thanks!

    Quote Originally Posted by macropod View Post
    That's quite simple
    Well, I wouldn't have managed without your help. :-)

    Thank you very much! It works great.

  5. #4
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi there

    in the past couple of days, Microsoft Word crashes sometimes when I execute the macro.
    It happens on my computer and on the computer of a colleague, both on the same documents.
    Until now, it always happened with .doc and never with .docx, but there are also .doc-files where it works.
    Crashing = the mouse pointer changing rapidly between the pointer and the turning circle, until you get to see 'not responding' and have to restart the whole program.
    Do you have any explanation or a solution?
    Thanks!

  6. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    On a very large document with lots of highlighting, Word may appear to hang while the macro runs. Just give it time...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #6
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's indeed what I thought the first time. But when a five-page document is still hanging after a visit to the toilet, I think there is something else going on.
    (There was indeed a lot of highlighting in the document - more than half. But three minutes seems like too long.)

  8. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    For me, a 22,600-character 5-page document of random, mostly-highlighted, text takes less than 1-second to process. I suggest you check what else is running on your system and/or that you repair the Office installation.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #8
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Still not working

    Hi Paul

    sorry to bother you again, but this keeps crashing sometimes. Even on very short docs.
    It seems to happen only when the text is in tables. Do you have a solution?

    Thanks!

    Koen

  10. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try changing:
    .Forward = True
    and:
    .Collapse wdCollapseEnd
    to:
    .Forward = False
    and:
    .Collapse wdCollapseStart
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #10
    New Lounger
    Join Date
    Dec 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Great, thanks!

    I tested it on a document where it crashed, and it seems to work.

    Many thanks again for your efforts.

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
  •