Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Context Menu VBA / Excel

Posted on 2010-11-23
4
Medium Priority
?
774 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

660 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