Help with personal.xlsb workbook

pingpongplaya10

New Member
Joined
Aug 21, 2011
Messages
8
Hello all,

I placed the following code in the Personal.xlsb file however it does not seem to be working (it worked in a normal spreadsheet). It's supposed to create a menu item with right-clicking on a cell. Can someone please take a look and explain what i'm doing wrong? Thanks in advance.

Code in the "ThisWorkbook" file of Personal.xlsb:
Code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    'remove out custom menu before we leave
    Run ("DeleteCustomMenu")
    
End Sub
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    
    Run ("DeleteCustomMenu")   'remove possible duplicates
    Run ("BuildCustomMenu")    'build new menu
    
End Sub

Code in the "Module1" file of Personal.xlsb:
Code:
Option Explicit
Private Sub BuildCustomMenu()
Dim ctrl As CommandBarControl
Dim btn As CommandBarControl
Dim i As Integer
    
    'add a 'popup' control to the cell commandbar (menu)
    Set ctrl = Application.CommandBars("Cell").Controls.Add _
                (Type:=msoControlButton, Before:=1)
    ctrl.Caption = "Sum Cells"
    ctrl.Tag = "test"
    ctrl.OnAction = "SumCells"
End Sub
Private Sub DeleteCustomMenu()
Dim ctrl As CommandBarControl
    
    'go thru all the cell commandbar controls and delete our menu item
    For Each ctrl In Application.CommandBars("Cell").Controls
        If ctrl.Caption = "Sum Cells" Then ctrl.Delete
    Next
    
End Sub
Private Sub SumCells()
Dim EndCell As String
Dim StartCell As String, StartCell2 As String
StartCell = ActiveCell.Address
StartCell2 = ActiveCell.Offset(-1, 0).Address
Range(ActiveCell.Address, Selection.End(xlUp)).Select
EndCell = Selection.End(xlUp).Address
    
Range(StartCell).Value = "=sum(" & EndCell & ":" & StartCell2 & ")"
Range(StartCell).Select
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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