Can I skip application-level event-triggered macros if that event triggered a workbook-level event

taigovinda

Well-known Member
Joined
Mar 28, 2007
Messages
2,639
Hi,

I have a workbook-level double-click event that I put into a certain workbook awhile ago.

It checks if there is a record identifier in a certain format either in the target cell or in the current range, within the double-clicked row; if so it queries an SQL server to find backup documentation for that record identifier and opens the document(s) in internet explorer.

Turns out this procedure, which is working fine, would be good to have in other workbooks or just to have on all the time. So, I inserted it into an existing add-in that can be redistributed to all the folks that would use it. I did that using the App double-click event in the ThisWorkbook module of the add-in, as described here: http://www.cpearson.com/excel/appevent.aspx ...that is working fine too - but I don't like the way the two are interacting.

My question is... if people are double-clicking in workbooks that already have the event-driven macro coded into there, the event will fire twice - once at the workbook level and once at the application level from the add-in. Then it will try to find and open the backup documents twice. Given that the workbooks firing the event are already coded and distributed all over the place so I can't change that code, is there a way for my add-in to know that this particular double-click already caused a workbook-level event to trigger a macro? I could try to read the query command string from the active workbook and see if it contains the same record identifier that my add-in would be querying for, but wondered if there is a more universal way to do it.

Thanks for any help!

Tai
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The only workaraound I can think of is to override the default double-clicking events in workbooks that already have the event-driven macro coded into.

The following code should be placed in the
ThisWorkbook module of the add-in :

Code:
Option Explicit

Private WithEvents Wb As Workbook
Private WithEvents cmb As CommandBars

Private Sub Workbook_Open()
    Call cmb_OnUpdate
End Sub

Private Sub cmb_OnUpdate()
    Set cmb = Application.CommandBars
    Set Wb = ActiveWorkbook
End Sub

Private Sub Wb_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Application.OnTime Now, Me.CodeName & ".cmb_OnUpdate"
    Debug.Print "You double-clicked sheet: " & Sh.Name & " of " & "Workbook : " & Sh.Parent.Name
    [B][COLOR=#008000]'Run your SQL query code here....
[/COLOR][/B]    End
End Sub


Unfortynately, the code uses the End statement which reinitializes all the module-level variables and intantiated classes. If that is not a problem for you then you can use it.
 
Last edited:
Upvote 0
Hi Jaafar, this is definitely universal. I'm going to give it a try and see if it cancels anything that people will miss.

Thanks!

Tai
 
Upvote 0
Your workbook level event could test for the presence of the Application object that drives that routine. If the App object is present, the WB level routine exits.
 
Upvote 0
Your workbook level event could test for the presence of the Application object that drives that routine. If the App object is present, the WB level routine exits.
The problem is that he can't change the codes in the workbooks :
Given that the workbooks firing the event are already coded and distributed all over the place so I can't change that code,...
 
Upvote 0
The app level event fires after the workbook level event.
If the permissions are set appropriately, it could look through the workbooks to see if one of them has the WB. double click code
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top