Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Add Menu to a VBA Form

How can I add a popup menu to a VBA Form?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Add Menu to a VBA Form

Hello Rajesh
Yes, here's a sample code:
'** Userform ****
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
DisplayMenu
End If
End Sub
Private Sub UserForm_Terminate()
DeleteMenu
End Sub
'** Module ****
Const MenuName As String = "USFMenu"
Sub DisplayMenu()
DeleteMenu
Dim cb As CommandBar
Set cb = CommandBars.Add(MenuName, msoBarPopup, False, True)
With cb
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro1"
.FaceId = 71
.Caption = "Menu 1"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro2"
.FaceId = 72
.Caption = "Menu 2"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro3"
.FaceId = 73
.Caption = "Menu 3"
End With
End With
Application.CommandBars(MenuName).ShowPopup
End Sub
Sub DeleteMenu()
On Error Resume Next
CommandBars(MenuName).Delete
On Error GoTo 0
End Sub
Sub Macro1()
MsgBox "Macro 1 running"
End Sub
Sub Macro2()
MsgBox "Macro 2 running"
End Sub
Sub Macro3()
MsgBox "Macro 3 running"
End Sub

HTH
Cordially
Pascal

"Rajesh Sivadasan" <Rajesh a écrit dans
le message de ...
How can I add a popup menu to a VBA Form?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Add Menu to a VBA Form

Thanks Very much Pascal. Great Job!!!

"papou" wrote:

Hello Rajesh
Yes, here's a sample code:
'** Userform ****
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
DisplayMenu
End If
End Sub
Private Sub UserForm_Terminate()
DeleteMenu
End Sub
'** Module ****
Const MenuName As String = "USFMenu"
Sub DisplayMenu()
DeleteMenu
Dim cb As CommandBar
Set cb = CommandBars.Add(MenuName, msoBarPopup, False, True)
With cb
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro1"
.FaceId = 71
.Caption = "Menu 1"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro2"
.FaceId = 72
.Caption = "Menu 2"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Macro3"
.FaceId = 73
.Caption = "Menu 3"
End With
End With
Application.CommandBars(MenuName).ShowPopup
End Sub
Sub DeleteMenu()
On Error Resume Next
CommandBars(MenuName).Delete
On Error GoTo 0
End Sub
Sub Macro1()
MsgBox "Macro 1 running"
End Sub
Sub Macro2()
MsgBox "Macro 2 running"
End Sub
Sub Macro3()
MsgBox "Macro 3 running"
End Sub

HTH
Cordially
Pascal

"Rajesh Sivadasan" <Rajesh a écrit dans
le message de ...
How can I add a popup menu to a VBA Form?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add Menu to a VBA Form


hi pascal

the code u did was fantastic... never knew this was possible... just
question here... how can i find out what number will show whic
faceid...? or is it possible to show the faceid as a specified pictur
or specified word like "Country"???

Cheer

--
hc
-----------------------------------------------------------------------
hce's Profile: http://www.excelforum.com/member.php...nfo&userid=351
View this thread: http://www.excelforum.com/showthread.php?threadid=26309

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Add Menu to a VBA Form

how can i find out what number will show which faceid...?

You might grab BtnFaces.zip from http://www.bmsltd.ie/MVP/Default.htm

--
Jim Rech
Excel MVP




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Add Menu to a VBA Form

Try John Walkenbach's FaceId add-in

http://www.j-walk.com/ss/excel/tips/tip67.htm

--

HTH

RP

"hce" wrote in message
...

hi pascal

the code u did was fantastic... never knew this was possible... just a
question here... how can i find out what number will show which
faceid...? or is it possible to show the faceid as a specified picture
or specified word like "Country"???

Cheers


--
hce
------------------------------------------------------------------------
hce's Profile:

http://www.excelforum.com/member.php...fo&userid=3518
View this thread: http://www.excelforum.com/showthread...hreadid=263098



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add Menu to a VBA Form


hi jim & bob

thanks for your help... so there's no way we can specify our our image
or caption...???

cheer

--
hc
-----------------------------------------------------------------------
hce's Profile: http://www.excelforum.com/member.php...nfo&userid=351
View this thread: http://www.excelforum.com/showthread.php?threadid=26309

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Add Menu to a VBA Form

Yes you can. Create a picture and insert it into a worksheet somewhere
(InsertPictureFrom File), and name them. Then to add them to the toolbar,
use

cbTable.Shapes(shapename).CopyPicture
cbCtl.PasteFace

where cbTable is the codename of the sheet containing the picture, shapename
is the name of the shape, such as 'Picture 30', and cbCtl is an object
variable for the control being added.


--

HTH

RP

"hce" wrote in message
...

hi jim & bob

thanks for your help... so there's no way we can specify our our images
or caption...???

cheers


--
hce
------------------------------------------------------------------------
hce's Profile:

http://www.excelforum.com/member.php...fo&userid=3518
View this thread: http://www.excelforum.com/showthread...hreadid=263098



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add Menu to a VBA Form


hi bob

thanks for your help but i tried to modify pascal's code but was no
able to get your code working together...

first i wasn't able to change the picture's name so i used the defaul
"Picture 1"... second when i put the picture name where you specified
i must take out the space if not there would be an error... i trie
another way and that is to put "Picture 1" like this and it was ok..
lastly, i didn't manage to get it work though i tried various ways...

my vb is not that good so maybe that's y i wasn't able to get it t
work... by the way, is it possible to use words... such as "Country"??


cheer

--
hc
-----------------------------------------------------------------------
hce's Profile: http://www.excelforum.com/member.php...nfo&userid=351
View this thread: http://www.excelforum.com/showthread.php?threadid=26309

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
Trying to get a User Form to activate off a drop down menu Rcarper Excel Discussion (Misc queries) 2 October 2nd 09 02:04 PM
What replaces the Data/form menu item in Excel 2007? NJJorgy New Users to Excel 3 November 16th 07 10:44 PM
How do I delete a document name form word menu Fred D propp Setting up and Configuration of Excel 1 July 21st 07 09:36 AM
Opening a Form from send menu? Noggin[_5_] Excel Programming 0 July 4th 04 10:21 AM
Right click menu in my form kvenku Excel Programming 0 April 7th 04 01:18 PM


All times are GMT +1. The time now is 04:11 AM.

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

About Us

"It's about Microsoft Excel"