I miss the end of the sheet of typing paper, so ...

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15651
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

I miss the end of the sheet of typing paper, so ...

Post by ChrisGreaves »

I re-crafted a little gem from way back:
(later) AFAIK this still works, but I have a better version in the pipeline)

Code: Select all

' Place this commented sub in the "ThisDocument" module
'Private Sub Document_Open()
'    Call AssignMyKeys
'End Sub
' The code below goes into a regular code module; VBE Insert, Module.
Const lngcBaseWordCount As Long = 340
Const lngcMaxWordCount As Long = 300
Sub AssignMyKeys()
    KeyBindings.Add KeyCode:=BuildKeyCode(Arg1:=wdKeyReturn), KeyCategory:=wdKeyCategoryMacro, Command:="Test1"
End Sub
Sub test1()
    If (ActiveDocument.Words.Count - lngcBaseWordCount) > lngcMaxWordCount Then
        MsgBox "Exceeded " & Str(lngcMaxWordCount) & " words."
    Else
    End If
    Selection.TypeText vbCrLf
End Sub
My task is to perform a series of brain-dumps of ideas into short essays of about 300 words each (hence "lngcMaxWordCount").
The document template arrives with about 340 words of boilerplate text (hence "lngcBaseWordCount")
I have "tied" a little macro, "test1" to the Enter key.
Each time I tap the Enter key to start a new paragraph, the macro checks to see if I have exceeded my word-count limits.
Last edited by ChrisGreaves on 14 Nov 2011, 13:09, edited 1 time in total.
He who plants a seed, plants life.

User avatar
BobH
UraniumLounger
Posts: 9300
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: I miss the end of the sheet of typing paper, so ...

Post by BobH »

Great idea. Now you need to modify it to warn you at 275 words so you can creep up on it. :flee
Bob's yer Uncle
(1/2)(1+√5)
Dell Intel Core i5 Laptop, 3570K,1.60 GHz, 8 GB RAM, Windows 11 64-bit, LibreOffice,and other bits and bobs

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15651
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: I miss the end of the sheet of typing paper, so ...

Post by ChrisGreaves »

BobH wrote:Great idea. Now you need to modify it to warn you at 275 words so you can creep up on it. :flee
:rofl:
Hi Bob; since then, the code has undergone a few changes and, surprise surprise, welcomed a bug.
I'll be posing a new version within a day or two when things settle down.
He who plants a seed, plants life.