Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If bCellIsInsideRange(Target, Range("DrillThruPoss")) Then
If [b]Not (Application.CommandBars("cell").Controls("Drill").Enabled)[/b] Then
MsgBox ("Sorry, you cannot drill down on this cell")
Else
Call StartOfLongUpdate
[b]Application.CommandBars("cell").Controls("Drill").Execute[/b]
If ActiveSheet.Range("A1").Value = "FirstSightDrillThru" Then
Call DrillThruFormatSheet
End If
Call FinishedLongUpdate
End If
End If
This is the background to this bit of code.
When someone double clicks on a cell on the sheet, it calls this event. What gets passed in as Target will be the cell that they clicked on.
It calls a function I wrote to see if the cell that they clicked on is inside the Range called DrillThruPoss. This is just a range I predefined on the sheet of all cells where Drill Thru is possible. This is just a quick way of finding out whether they are double clicking in the write area.
It then sees whether the Drill menu option is enabled on the context sensitive menu for that cell. This is the menu that would pop up if you right clicked on the cell. It will always have a mix of Excel and TM1 options. If the Drill option is enabled then you know that there is a Drill Thru Rule applying to that cell.
If there isn't then it puts up a message box
If there is then it runs Controls("Drill").Execute. To avoid any confusion, this doesn't run a Drill Thru process, instead it pops up a menu to allow them to choose from the available Drill Thrus. We generally have two processes. However, from what I can remember, if there is only one Drill Thru process then I think it will run that Drill Thru process straight away, without prompting.
After running the Drill Thru, it will have opened another workbook and the active sheet will give the results of the Drill Thru.
What I do in the SQL is to make the first column a hard coded literal, ie
SELECT "FirstSightDrillThru" as FirstSightDrillThru, SEGNUMB1 as Entity, ...
Then by checking to see whether the value in Cell A1 is FirstSightDrillThru I can guard against the case where something went wrong with the DrillThru and avoid trying to reformat the calling report, instead of the Drill Thru Sheet.
As David Usherwood points out, the main point of doing all this is that it allows you to format the result of the Drill Thru, to bold headings, format numbers, set Freeze Panes, etc. Unfortunately the annoying thing about the normal Right Click Drill, is that it doesn't trigger any sort of event that would allow you to detect that Drill Thru has taken place. There is no Workbook added or any other sort of Event. This method allows you to do that, and double clicking is arguably more natural for most users than right clicking. They also don't have to contend with finding Drill on a menu that has 12 or so other options.
Regards
Paul Simon