Customised ContextMenus Not Working in 2007


New Member
Oct 6, 2010

I've recently customised some of the contextmenus within Excel (2003), including the Cell and Query menus. This is working fantastically well, giving some better functionality. I've saved the workbook as an Add-In.

I need to use the same code within Excel 2007 as well. The Add-In is there in 2007, and the items appear on the contextmenus OK. However, when I click on any of the new custom items, I get the following error message

'Argument not optional'

I'm not sure where I'm going wrong.

Here's a bit of the code I'm trying to use:

Sub AddToCellMenu()
    Dim ContextMenu As CommandBar
    Dim MySubMenu As CommandBarControl

    Call DeleteFromCellMenu

    Set ContextMenu = Application.CommandBars("Cell")

    ContextMenu.Controls.Add Type:=msoControlButton, ID:=3, before:=1

    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=2)
    .OnAction = "FormatReport"
    .FaceId = 107
    .Caption = "Format Report"
    .Tag = "My_Cell_Control_Tag"
    End With
End Sub
And the FormatReport Sub:
Sub FormatReport()
    Dim intColumnCount As Integer
    'Application.ScreenUpdating = False
    On Error Resume Next
    range(Selection, Selection.End(xlToRight)).Select
    Selection.Interior.ColorIndex = 36
End Sub
I've omitted a lot of the code, and there are other subs also, but the same applies to each of them.

Anyone have any suggestions?


Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...