Solved

Context Menu VBA / Excel

Posted on 2010-11-23
4
767 Views
Last Modified: 2012-05-10
Hi Guys

I'm trying to add a few menu items to my right click context menu in excel but im having a few problems - my current code is attached.

No matter how i tweak this code, it errors with "Object Variable or With Block variable not set".

Any ideas?

James
Dim JMButton As CommandBarButton
    Dim JMControl As CommandBarControl
    
    Application.CommandBars("Cell").Reset
   
    Set JMButton = CommandBars("Cell").Controls.Add(Type:=msoControlButton)
        With JMButton
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "JM_GridLines"
        .Caption = ""
        .TooltipText = "Removes gridlines and sets zoom to 85%"
        .Style = msoButtonIconAndCaption
        .FaceId = 485
    End With
   
   
    Set JMControl = CommandBars("Cell").Controls.Add(Type:=msoControlPopup, Temporary:=True)
    With JMControl
        .Caption = "&Misc"

        'Adds Menu Item - Checks selection for duplicates and highlights them
        With .Controls.Add(Type:=msoControlButton)
            .Caption = "Duplicate Check"
            .OnAction = "'" & ThisWorkbook.Name & "'!" & "JM_Duplicates"
            .FaceId = 1098
        End With
        'Adds Menu Item - Checks selection for duplicates in single column
        'and highlights them and adds the word 'duplicate' to following column
        With .Controls.Add(Type:=msoControlButton)
            .Caption = "Duplicate Check - Single Column"
            .OnAction = "'" & ThisWorkbook.Name & "'!" & "JM_DuplicatesSingle"
            .FaceId = 1098
        End With

   End With

Open in new window

0
Comment
Question by:Delerium1978
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34195718
Which line?
0
 

Author Comment

by:Delerium1978
ID: 34195747
Set JMButton = CommandBars("Cell").Controls.Add(Type:=msoControlButton)
0
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 34195772
Does this make any difference?
Set JMButton = Application.CommandBars("Cell").Controls.Add(Type:=msoControlButton)

Open in new window

0
 

Author Closing Comment

by:Delerium1978
ID: 34195818
Yes that works - i cant beleive i missed something so simple. Another pair of eyes always helps - thanks a lot :)

J
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question