Solved

Trapping a mouseclick and mousemove event in VB

Posted on 2008-10-23
8
331 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:swap811
  • 5
  • 3
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22786403
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
 

Author Comment

by:swap811
ID: 22793673
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
 

Author Comment

by:swap811
ID: 22793934
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22794557
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:swap811
ID: 22794655
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
 

Author Comment

by:swap811
ID: 22794670
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 22794739
You can use a macro named AutoExec in a code module:
Sub AutoExec()

    Register_Event_Handler

End Sub

Open in new window

0
 

Author Comment

by:swap811
ID: 22794750
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

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now