Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2021, 12:50 AM
Maxx Maxx is offline Coloring of textbox contents starting from a certain number of words Windows 10 Coloring of textbox contents starting from a certain number of words Office 2016
Novice
Coloring of textbox contents starting from a certain number of words
 
Join Date: Apr 2021
Posts: 1
Maxx is on a distinguished road
Default Coloring of textbox contents starting from a certain number of words

Hello all,



below macro colors all letters of a word file in red, as soon as the word count exceeds the value ten. However, I would like this not to be counted for the entire text of a Word document, but to count and color separately for ten textboxes that are in a Word document. Can anyone help me with this? Thanks in advance!

Code:
Sub AutoOpen()
    NumberOfWords
End Sub
 
Sub NumberOfWords()
    Dim lngWords As Long
    Dim myRange As Range
    Dim lngLimit As Long
     
    lngLimit = 10
     
    With Word.Application
        If .Windows.Count > 0 Then
            Set myRange = ActiveDocument.Content
            lngWords = myRange.ReadabilityStatistics(1).Value
            .Caption = Format(lngWords, "##,##0") & " words - Microsoft Word"
            If lngWords > lngLimit Then
                Set myRange = Selection.Range
                myRange.WholeStory
                myRange.Font.ColorIndex = wdRed
            Else
                Set myRange = Selection.Range
                myRange.WholeStory
                myRange.Font.ColorIndex = wdBlack
            End If
        Else
            .Caption = "Microsoft Word"
        End If
        .OnTime Now + TimeValue(OnTm(lngWords)), "NumberOfWords"
    End With
End Sub
 
Private Function OnTm(ByVal lngWd As Long) As String
    Select Case lngWd \ 1000
        Case 0 To 10
            OnTm = "00:00:01"
        Case 11 To 20
            OnTm = "00:00:05"
        Case 21 To 30
            OnTm = "00:00:10"
        Case 31 To 40
            OnTm = "00:00:15"
        Case Else
            OnTm = "00:00:20"
    End Select
End Function

Last edited by macropod; 04-17-2021 at 03:11 AM. Reason: Added code tags & removed code image
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting number later in doc alwann Word 2 03-06-2019 04:06 AM
Coloring of textbox contents starting from a certain number of words Emailing textbox contents only naeemakhtar Word VBA 3 04-06-2016 06:31 AM
Number listing starting from second word rehan0129 Word 0 03-18-2015 10:46 AM
how to save contents in textbox in VB2013 form into a Word document? saltlakebuffalo Word VBA 6 12-10-2014 06:12 PM
Coloring of textbox contents starting from a certain number of words Search for words starting in capitals surreytom Word VBA 3 04-01-2012 01:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:11 PM.


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