(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
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.