Trapping a mouseclick and mousemove event in VB

hi guys,
I want to identify column width change of a table in a macro .
for that  I want to trap a mouse click event on document without adding any content control.
Also  further i need to trap a mouse move event so please help me on that also.

If u know some better approach for this please do let me know.Thanks a lot in advance
swap811Asked:
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.

GrahamSkanRetiredCommented:
There are no mouse methods exposed in Word VBA. The best I could suggest is to create a Class module and to test the width in the WindowSelectionChange event.

You will need a declaration such as this in the module:

Dim WithEvents wdApp As Word.Application

and you need to have set wdApp equal to the current Application during the session.

Set wdApp = Application
0
swap811Author Commented:
Sorry I am not getting how to use it.Can u please explain me in detail or if possible do send me some sample code .
0
swap811Author Commented:
This is what I have done .wordapp is declared global.please tell me how to link with the document as it is not working currently.


Dim WithEvents wdApp As Word.Application
Dim x As New Class1



Private Sub Class_Initialize()
Set wdApp = Word.Application
Set ThisDocument = ActiveDocument


MsgBox "testing1"



End Sub

Private Sub wdApp_DocumentOpen(ByVal Doc As Document)

Set wdApp = Word.Application


End Sub

Private Sub wdApp_NewDocument(ByVal Doc As Document)
 MsgBox "testing"
End Sub

Private Sub wdApp_Quit()

End Sub

Private Sub wdApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
MsgBox "testing"
End Sub

Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
    MsgBox "testing"
End Sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GrahamSkanRetiredCommented:
I have tweaked your code a tiny bit.
'Put this code in a module and run it.
Sub Register_Event_Handler()
    Dim X As New Class1
 
    Set X.wdApp = Application
    MsgBox "wdApp events registered in: " & X.wdApp.Name
End Sub
 
'This is the code for the class module
 
Option Explicit
 
Public WithEvents wdApp As Word.Application
 
 
Private Sub wdApp_NewDocument(ByVal Doc As Document)
    MsgBox "testing"
End Sub
 
 
Private Sub wdApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
    MsgBox "testing"
End Sub
 
Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
    MsgBox "testing"
End Sub

Open in new window

0
swap811Author Commented:
it is giving error in module's code with the following line
Set X.wdApp = Application
    It is saying that wdApp member not found.I have added the module's code in newly created module.
Do u have any other better approach to the problem.please do let me know.
0
swap811Author Commented:
oh I had made 1 mistake. Now it is working.thanks a lot.Now my requirement is that when i open a word my macro should automatically start.please solve this problem also.Thanks again in advance
0
GrahamSkanRetiredCommented:
You can use a macro named AutoExec in a code module:
Sub AutoExec()
    Register_Event_Handler
End Sub

Open in new window

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
swap811Author Commented:
the windows events r not working still and that is what i need.what must I do for that.please do let me know
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
Visual Basic Classic

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.