ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA-Make Custom Menu Item Fire (https://www.excelbanter.com/excel-programming/305130-vba-make-custom-menu-item-fire.html)

d_rodman

VBA-Make Custom Menu Item Fire
 
Hello,
I am trying to make my userform "frmSearch" able to be fired up fro
the regular menu. It is loaded right away, but the user needs to b
able to close it and reopen whenever they need it. My code creates th
Menu item, but when I click on it, it does nothing. I have inserted m
code below. I need help by the "TODO: show search agentThanks i
advance, I appreciate any help.

In "This Workbook:"
Private Sub Workbook_Open()
frmSearch.Show

Dim con

For Each con In Application.CommandBars(1).Controls
If con.Caption = "Agent" Then
con.Delete
End If
Next

With Application.CommandBars(1).Controls.Add(msoControl Popup)
.Caption = "Agent"
.OnAction = "Show_frmSearch" 'TODO: show search agent
End With

In a module:
Public Sub Show_frmSearch()
frmSearch.Show
End Su

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

VBA-Make Custom Menu Item Fire
 
if you code is as it is shown in your email, you need to modify it to look
like this:

With Application.CommandBars(1).Controls.Add(msoControl Popup)
.Caption = "Agent"
.OnAction = "Show_frmSearch" 'TODO: show search agent
End With

--
Regards,
Tom Ogilvy

"d_rodman " wrote in message
...
Hello,
I am trying to make my userform "frmSearch" able to be fired up from
the regular menu. It is loaded right away, but the user needs to be
able to close it and reopen whenever they need it. My code creates the
Menu item, but when I click on it, it does nothing. I have inserted my
code below. I need help by the "TODO: show search agentThanks in
advance, I appreciate any help.

In "This Workbook:"
Private Sub Workbook_Open()
frmSearch.Show

Dim con

For Each con In Application.CommandBars(1).Controls
If con.Caption = "Agent" Then
con.Delete
End If
Next

With Application.CommandBars(1).Controls.Add(msoControl Popup)
Caption = "Agent"
OnAction = "Show_frmSearch" 'TODO: show search agent
End With

In a module:
Public Sub Show_frmSearch()
frmSearch.Show
End Sub


---
Message posted from http://www.ExcelForum.com/




d_rodman[_2_]

VBA-Make Custom Menu Item Fire
 
Whoops my bad, I actually had it correct in my code. Lost the "." i
the cut and paste transistion. Sorr

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

VBA-Make Custom Menu Item Fire
 
Your code worked fine for me.

I didn't create the button in the workbook_open event, but using a normal
module worked and since you use Application.Commandbars in the Open event,
it should work. Also, you said the button is getting created successfully,
so I assume it is working.

I assume the Show macro is in the same workbook.

--
Regards,
Tom Ogilvy


"d_rodman " wrote in message
...
Whoops my bad, I actually had it correct in my code. Lost the "." in
the cut and paste transistion. Sorry


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com