Heshamello
New Member
- Joined
- Mar 10, 2016
- Messages
- 1
Hello Excel Masters
This is my first question on Mr Excel I hope You can Help me
I am new to VBA and I whenever I come across a new code I try to simplify before learning
one of the things I do is I remove all With - End With and replace them with the original line so I can better understand the code
While I was learning how to do popup menus I found the below code that is working perfectly
As usual I tried to remove all the With and replace it with the Original Line so my code was like this
but I always get the error : Run-time error '5': Invalid Procedure call or argument.
I know it's a weird question but I always learnt like this and I am going mad trying to figure out the problem with this
Thanks in advance
This is my first question on Mr Excel I hope You can Help me
I am new to VBA and I whenever I come across a new code I try to simplify before learning
one of the things I do is I remove all With - End With and replace them with the original line so I can better understand the code
While I was learning how to do popup menus I found the below code that is working perfectly
Code:
[COLOR=#3366CC]Sub PopUpMenu()[/COLOR]
With Application.CommandBars.Add(Name:="Pop1", Position:=msoBarPopup, _
MenuBar:=False, Temporary:=True)
With .Controls.Add(Type:=msoControlButton)
.Caption = "Button 1"
.FaceId = 71
.OnAction = msgbox ("Yahooooo, It worked")
End With
End With
End Sub
As usual I tried to remove all the With and replace it with the Original Line so my code was like this
Rich (BB code):
Rich (BB code):
Sub PopUpMenu()
Application.CommandBars.Add(Name:="Pop1", Position:=msoBarPopup, MenuBar:=False, Temporary:=True).Controls.Add(Type:=msoControlButton).Caption = "Button 1"
Application.CommandBars.Add(Name:="Pop1", Position:=msoBarPopup, MenuBar:=False, Temporary:=True).Controls.Add(Type:=msoControlButton).FaceId = 71
Application.CommandBars.Add(Name:="Pop1", Position:=msoBarPopup, MenuBar:=False, Temporary:=True).Controls.Add(Type:=msoControlButton).OnAction = MsgBox("Yahooooo, It worked")
End Sub
but I always get the error : Run-time error '5': Invalid Procedure call or argument.
I know it's a weird question but I always learnt like this and I am going mad trying to figure out the problem with this
Thanks in advance