+ Reply to Thread
Results 1 to 9 of 9

Don't make double items in context menu

  1. #1
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Don't make double items in context menu

    Hello,

    Under the right-click menu I added an item on a specific range in Excel. The location in Excel knows what to add into the menu (a for creating a heading or a new line item). When I right-click somewhere else the custom menu is removed. So far so good.

    When a right-click follows a right-click multiple times the menu item is added again and again. The routine should check weather the items exists and if now, create.

    This is what I made (with some help of 'Google')

    Right-click code:
    Please Login or Register  to view this content.
    Create and remove code:
    Please Login or Register  to view this content.
    Does anybody know what I did wrong or how I can improve this?

    Thank you in advance!
    Erik
    Attached Images Attached Images

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Don't make double items in context menu

    You haven't provided all of those procedures referred to in the right-click event.

  3. #3
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Don't make double items in context menu

    Quote Originally Posted by Bob Phillips View Post
    You haven't provided all of those procedures referred to in the right-click event.
    The code for creating headings is nearly the same as for creating new line items. That's why I didn't insert this:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Don't make double items in context menu

    Zo kan het ook...
    Instead of adding/deleting buttons, I'd prefer to make them visible/invisible.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by snb; 01-07-2011 at 11:52 AM.



  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Don't make double items in context menu

    Personally I find it easier to create a new commandbar and show that instead of modifying the built-in one.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Don't make double items in context menu

    Thank you for your (fast!) advices. I'll try this myself...
    Actually I was already very pleased with this initial result as I am a real beginner in VBA.

  7. #7
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Don't make double items in context menu

    Quote Originally Posted by snb View Post
    Instead of adding/deleting buttons, I'd prefer to make them visible/invisible.
    Please Login or Register  to view this content.
    I just tried your suggestion and copied your code but receive this error: 'Compile Error: Variable Not Defined' at the position 'msbutton'. What did I do wrong here?

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Don't make double items in context menu

    it should be msoControlButton not just mosButton.

  9. #9
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Don't make double items in context menu

    Great! Replacing mosButton with msoControlButton worked! Now I'll continue my puzzle to avoid double items in the context menu.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1