View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default Delete Row and Auto Subtract

hon,
You want the popup menu and associated routines available
for all workbooks, right?

See
http://groups.google.com/group/micro...37c15304ea45c2
in which Tom O refers to
http://support.microsoft.com/kb/q158244/
which is handling application events. From that I got
the following (on XL97) which should do what you want.
In a separate workbook (Book1), add a Class module (Class1) with
Option Explicit
Public WithEvents AppEvent As Application

Private Sub AppEvent_SheetBeforeDoubleClick( _
ByVal Sh As Object, _
ByVal Target As Excel.Range, _
Cancel As Boolean)

Cancel = True
Dim CB1 As CommandBar, CBC1 As CommandBarControl
On Error Resume Next
Application.CommandBars("XYZ").Delete
On Error GoTo 0 ' restore error processing
Set CB1 = Application.CommandBars.Add("XYZ", msoBarPopup, False,
True)
Set CBC1 = CB1.Controls.Add(msoControlButton)
CBC1.Style = msoButtonCaption
CBC1.Caption = "Doit"
CBC1.OnAction = "SubDoit"
Application.CommandBars("XYZ").ShowPopup
End Sub

On the same workbook, add a Standard module (Module1) with
Option Explicit
Dim MyObject As Class1

Sub LoadEventHandler()
Set MyObject = New Class1
Set MyObject.AppEvent = Application
MsgBox "Event handler is loaded"
End Sub

Sub SubDoit() ' your stuff goes here
Dim WbName$, WsName$
WbName = ActiveSheet.Parent.Name
WsName = ActiveSheet.Name
MsgBox "You double clicked" & vbCrLf & _
WbName & vbCrLf & _
WsName & vbCrLf & _
ActiveCell.Address
Workbooks(WbName).Sheets(WsName).Cells(1, 1) = "Touch11"
Workbooks(WbName).Sheets("Sheet2").Cells(2, 2) = "Touch22"
End Sub

Then run LoadEventHandler and it's done!
You have to keep Book1 open in order to keep the event handler.
You could probably put book1 stuff in Personal.xls or an Add-In.

This is neat stuff!

hon123456 wrote:
Can I Change the code as follows:

Private Sub ActiveWorkbook.Worksheet2_BeforeRightClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
[makes a popup menu and does the .Popup]
End Sub

Thanks