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
LVL 4
vi_srikanthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.