Ambiguous error

F

famdamly

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 = "octane" Then icbc.Delete
Next icbc

With Application.CommandBars("cell").Controls _
Add(Type:=msoControlButton, before:=6, _
temporary:=True)
Caption = "Octane"
OnAction = "octane"
Tag = "octane"
End With
End Sub

I copied and pasted this from the VB help section in excel. It works
good by itself. If I copy and paste again and change all the "octanes"
to something else and change the (what I think is the name) of the Sub
ever so slightly it doesn't work. Can you have more than one
sub-routine in the worksheet code?

There must be a way to modify the name of the Sub and keep it working
in unison with the original. Beats me.
 
B

Bob Phillips

You cannot change the name of the procedure as that is known to Excel, and
it must be exact.

You have more than one logic path, but you put that all in the same
procedure, such as

If condition1 Then
action1
Elseif condition2 Then
action2
EndIf



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top