Link to home
Start Free TrialLog in
Avatar of vi_srikanth
vi_srikanth

asked on

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
Avatar of mdmackillop
mdmackillop

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
ASKER CERTIFIED SOLUTION
Avatar of mdmackillop
mdmackillop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vi_srikanth

ASKER

Thanks a lot.

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