• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 975
  • Last Modified:

VBA - Document Change/Key Press

Hi Friends

In Microsoft Word is there a way by which I can trap whenever a change(Insertion/Deletion/Modification) happens in my document? Is there a way in VBA to handle this?

If this is not possible, is there a way by which I can trap the key pressed in my document thru VBA?

Please help me.

Srik
0
vi_srikanth
Asked:
vi_srikanth
  • 3
1 Solution
 
mdmackillopCommented:
Hi,
Put the following code in ThisDocument module.  I don't know enough regarding problems looping macros like this continually, so its at your own risk.  The code will check each 5 seconds for a change, then show a message box and save it.  Change the interval/action to suit your needs
MD

Private Sub Document_Open()

Application.OnTime When:=Now + TimeValue("00:00:05"), _
    Name:="Check1"
   
End Sub


Sub Check1()
Application.OnTime When:=Now + TimeValue("00:00:05"), _
    Name:="Check2"
    If ActiveDocument.Saved = False Then
        MsgBox Now()
        ActiveDocument.Save
    End If
End Sub

Sub Check2()
Application.OnTime When:=Now + TimeValue("00:00:05"), _
    Name:="Check1"
    If ActiveDocument.Saved = False Then
        MsgBox Now()
        ActiveDocument.Save
    End If
End Sub
0
 
mdmackillopCommented:
Hi Srik,
Here's a simplified version.
MD

Private Sub Document_Open()
    CheckSave
End Sub

Sub CheckSave()
Application.OnTime When:=Now + TimeValue("00:00:05"), _
    Name:="CheckSave"
    If ActiveDocument.Saved = False Then
        MsgBox Now()
        ActiveDocument.Save
    End If
End Sub
0
 
vi_srikanthAuthor Commented:
Thanks a lot.

But, it is pity that there is no EVENT to handle this!
0
 
mdmackillopCommented:
I agree, It surprised me how little there was.
Thanks for the grade!
MD
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now