PDA

View Full Version : [SOLVED:] WindowBeforeDoubleClick



DennyCrane
11-15-2018, 06:39 AM
Hey there,

I hope you can help me with this problem, like you did with the last.

I want to use the double-Click-Event in Word and so i did the following:


i created a new class and named it "Doubleclick"

The Code in this class is the following:


Public WithEvents App As Word.Application

Private Sub App_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)

End Sub

Now, as far as i know, i have to register this new event by running the macro from any module:


Dim X As New Doubleclick
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub

But all I get is a runtime error 424: Object required. Where is my error?

Greets

Denny Crane

gmaxey
11-15-2018, 02:52 PM
I didn't help you with the last. Graham did.

In a class module named "clsDblClick" put:


Option ExplicitPublic WithEvents oApp As Word.Application
Private Sub oApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
MsgBox "Beep"
End Sub
Private Sub Class_Initialize()
Set oApp = Word.Application
End Sub

In a standard module put:

Option ExplicitDim X As clsDblClick
Sub Register_Event_Handler()
Set X = New clsDblClick
End Sub

DennyCrane
11-16-2018, 01:24 AM
I'm so sorry, but it isn't runnig.

I have a class Module Dclick, containing this:

Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
Dim oCC As ContentControl
Set oCC = Sel.Range.ParentContentControl
If Not oCC Is Nothing Then
If oCC.Tag = "1" Then Call Macro1
If oCC.Tag = "2" Then Call Macro2

End If
Cancel = False
End Sub


Private Sub Class_Initialize()
Set oApp = Word.Application
End Sub


In a standard module is this:

Option Explicit
Dim X As Dclick
Sub Register_Event_Handler()
Set X = New Dclick
End Sub

When i doubleclick in a contentcontrol tagged "1" Macro1 isn't running.

Where is my mistake?

gmaxey
11-16-2018, 02:43 AM
Ran fine here so I don't know what you are doing wrong.



Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
Dim oCC As ContentControl
Set oCC = Sel.Range.ParentContentControl
If Not oCC Is Nothing Then
If oCC.Tag = "1" Then Call Macro1
If oCC.Tag = "2" Then Call Macro2
End If
Cancel = False
End Sub


Private Sub Class_Initialize()
Set oApp = Word.Application
End Sub

Sub Macro1()
MsgBox "Test 1"
End Sub
Sub Macro2()
MsgBox "Test 2"
End Sub

DennyCrane
11-16-2018, 04:10 AM
put the handler in a new handler-only module.

Works great now.

Thank you für your help.:content: