View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Making menu item changes temporary

You could do something like this to get the Edit|Delete Sheet control:

Option Explicit
Sub testme01()
With Application.CommandBars("worksheet menu bar") _
.Controls("edit").Controls("Delete sheet")
.OnAction = ThisWorkbook.Name & "!Testme99"
End With
End Sub

And reset it with:

Application.CommandBars("worksheet menu bar") _
.Controls("edit").Controls("Delete sheet").Reset

But you might miss a few controls (like the one when you right click on the
worksheet tab).

When I looked at the id for this control, it looked like they were all 847.

Sub testme33()
Call ModDelete(myReset:=False) 'true to reset it back to normal.
End Sub

Sub ModDelete(myReset As Boolean)

Dim CmdBar As CommandBar
Dim myCtrl As CommandBarControl
Dim iCtr As Long
Dim myId As Variant
myId = Array(847)

For Each CmdBar In Application.CommandBars
For iCtr = LBound(myId) To UBound(myId)
Set myCtrl = CmdBar.FindControl(ID:=myId(iCtr), recursive:=True)
If Not myCtrl Is Nothing Then
If myReset Then
myCtrl.Reset
Else
myCtrl.OnAction = ThisWorkbook.Name & "!testme99"
End If
End If
Next iCtr
Next

End Sub

If you find any more "deletes", you can just add them to the myid = array()
line.



Randy Johnson wrote:

When I add a custom menu item using the Add method I know
I can make it temporary by setting the Temporary property
to True. This is good because I know when my Excel
Application Unloads that is it, they don't show up in
other workbooks.

I need to make some custom changes to Excel Menus (not
custom) though like setting the .OnAction property for
the "EditDelete Sheet" option to point to my own code. I
know how to do this but it affects not only my own
application but also all other spreadsheets that are
opened. I know I can use the Reset method when I close
the application but if for some reason it crashes and the
reset is run there is potential for sheets other sheets to
be affected and passed around and before you know it.....a
mess!!

So how can I make the change temporary to begin with? Is
it possible?

Thanks in advance!
RJ


--

Dave Peterson