Consulting

Results 1 to 5 of 5

Thread: WindowBeforeDoubleClick

  1. #1

    WindowBeforeDoubleClick

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    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?

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    put the handler in a new handler-only module.

    Works great now.

    Thank you für your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •