Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Limit number of words (2003)

    Dear All,

    I want to distribute empty doc to different user. I want to control the number of words (say 500) the users can type into that empty document. Is there a way (macro-wise) to do so? If there is, can anyone please help?

    Thank you in advance.

    Ridz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Limit number of words (2003)

    Keeping track of the number of words dynamically might be difficult (it is a feature in the Mac version of Word, and it's frequently recommended to turn it off because it diminishes performance).

    You can turn on the Word Count toolbar, but the user has to click the Recount button manually to update the count. Still, it gives the user a quick way to see whether he/she is near the limit.

    You could also hijack the File | Save and File | Save as menu options by creating macros named FileSave and FileSaveAs; you could issue a warning if the number of words is over 500, or even cancel the save operation. But such an approach is fragile - the user might disable macros.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Limit number of words (2003)

    Hi Ridz

    I got this of the web somewhere and then stupidl closed the page down and can't give you the reference. I have adjusted it for you to only have 500 words in a document... enjoy ( <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>Some of it could probably be cleaned out but it works

    Sub autoexec()
    NumberOfWords
    End Sub
    Sub NumberOfWords()
    Dim lngWords As Long
    Dim myRange As Range
    With Word.Application
    If .Windows.Count > 0 Then
    Set myRange = ActiveDocument.Content
    lngWords = myRange.ReadabilityStatistics(1).Value
    .Caption = Format(lngWords, "##,##0") & " words - Microsoft Word"
    Else
    .Caption = "Microsoft Word"
    End If
    .OnTime Now + TimeValue(OnTm(lngWords)), "NumberOfWords"
    End With
    If lngWords > 500 Then
    MsgBox "Too many words"
    ActiveDocument.Undo 1
    Exit Sub
    End If
    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
    Jerry

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Limit number of words (2003)

    Hi Jerry
    I was looking through your code and don't understand the bold portion of your Select Case command shown below. Can you help me out? <pre>Select Case lngWd 1000 </pre>

    Regards
    Don

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Limit number of words (2003)

    I have to admit, I don't know. I have found the original code now. There is an exclamation at the bottom of the page at this link:

    http://wordtips.vitalnews.com/Pages/T1280_...Word_Count.html
    Jerry

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Limit number of words (2003)

    According to my old VB/VBA book, differs from / in the following way:

    / = division that returns a real number result
    = division that returns an integer result

    The book doesn't specify how remainders are handled (i.e., rounded or truncated).

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Limit number of words (2003)

    Thanks Jefferson

    You always seem to have uncovered that hidden gem.
    Regards
    Don

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Limit number of words (2003)

    The operator truncates the result, i.e. 13 5 results in 2, not in 3.

    a b is equivalent to Fix(a / [img]/forums/images/smilies/cool.gif[/img].

Posting Permissions

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