Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Right-Click Menu Items -- Duplicate Entries

Hello,

I have VBA that adds items to my right-click menu upon opening the
spreadsheet, then deletes them upon closing. Unfortunately, I have
ended up with the items being repeated 5 times over. It currently is
not adding any more to this number, but I don't know how to get rid of
the extra items, or how to prevent this from happening in the future.
Any ideas? I think it may have occurred when I was creating a backup
of the current spreadsheet.

Private Sub Workbook_Open()
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Hide Shapes"
.OnAction = ThisWorkbook.Name & "!HideShapes"
.BeginGroup = True
End With
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Show Shapes"
.OnAction = ThisWorkbook.Name & "!ShowShapes"
.BeginGroup = True
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Cell").Controls("Hide Shapes").Delete
Application.CommandBars("Cell").Controls("Show Shapes").Delete
End Sub

Thanks,

Carroll Rinehart

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Right-Click Menu Items -- Duplicate Entries

Go to the VBE immediate window and just keep issuing the delete

Application.CommandBars("Cell").Controls("Hide Shapes").Delete

etc.

To make it more resolute for future, try this code


Private Sub Workbook_Open()
On Error Resume Next
Application.CommandBars("Cell").Controls("Hide Shapes").Delete
Application.CommandBars("Cell").Controls("Show Shapes").Delete
On Error Goto 0

With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Hide Shapes"
.OnAction = ThisWorkbook.Name & "!HideShapes"
.BeginGroup = True
End With
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Show Shapes"
.OnAction = ThisWorkbook.Name & "!ShowShapes"
.BeginGroup = True
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carroll" wrote in message
ups.com...
Hello,

I have VBA that adds items to my right-click menu upon opening the
spreadsheet, then deletes them upon closing. Unfortunately, I have
ended up with the items being repeated 5 times over. It currently is
not adding any more to this number, but I don't know how to get rid of
the extra items, or how to prevent this from happening in the future.
Any ideas? I think it may have occurred when I was creating a backup
of the current spreadsheet.

Private Sub Workbook_Open()
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Hide Shapes"
.OnAction = ThisWorkbook.Name & "!HideShapes"
.BeginGroup = True
End With
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Show Shapes"
.OnAction = ThisWorkbook.Name & "!ShowShapes"
.BeginGroup = True
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Cell").Controls("Hide Shapes").Delete
Application.CommandBars("Cell").Controls("Show Shapes").Delete
End Sub

Thanks,

Carroll Rinehart



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Right-Click Menu Items -- Duplicate Entries

Thanks Bob,

I really need to start using the VBE immediate window for testing and
running bits of code.

Thanks also for the improvements to the VBA.

Carroll

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Right-Click Menu Items -- Duplicate Entries

I found this code on some other site a long time ago and have since tweaked
it to suit my needs.

Instead of using Workbook_Open, try Worksheet_BeforeRightClick. You will
need to put this procedure in the code page for the worksheet instead of the
code page for ThisWorkbook.

You will notice that the CommandBars declaration now includes a .Tag
property. The FOR loop at the top makes use of the tag to find and delete
each custom CommandBar.

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim icbc As Object
For Each icbc In Application.CommandBars("Cell").Controls
If icbc.Tag = "show" Or icbc.Tag = "hide" Then icbc.Delete
Next icbc

With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Hide Shapes"
.OnAction = ThisWorkbook.Name & "!HideShapes"
.BeginGroup = True
.Tag = "hide"
End With
With Application.CommandBars("Cell").Controls.Add(tempo rary:=True)
.Caption = "Show Shapes"
.OnAction = ThisWorkbook.Name & "!ShowShapes"
.BeginGroup = True
.Tag = "show"
End With
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate entries nackgr Excel Discussion (Misc queries) 1 January 7th 11 12:15 PM
Deleting All Rows for Duplicate Entries Except Those With Most Items In Row foofoo Excel Discussion (Misc queries) 1 October 22nd 05 02:49 AM
Menu items added with menu item editor in older versions Michael Hoffmann Excel Discussion (Misc queries) 2 January 7th 05 01:40 PM
Adding a menu item right click menu when clicking on a single. Andoni[_28_] Excel Programming 0 September 2nd 04 10:23 PM
Adding menu to the mouse right click pop-up menu Jack Excel Programming 1 February 12th 04 05:23 AM


All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"