Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Menu for user forms

I have about 10 user forms. How can I create a new menu to select a user
form. The user forms contain prepared statements for use in a given area
(i.e. electrical, plumbing, grounds, etc)
The menu should be available only for this workbook.

Thanks
Hank


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Menu for user forms

This is pretty crude but should give you some ideas. CreateMenu should be
called from the Workbook_Activate event and DeleteMenu from the
Workbook_Deactivate event.

Sub CreateMenu()
Dim UFBar As CommandBar
Dim newButton As CommandBarButton
Set UFBar = CommandBars.Add("UserForms")
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm1"
.OnAction = "ShowUF1"
End With
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm2"
.OnAction = "ShowUF2"
End With
UFBar.Visible = True
End Sub

Sub ShowUF1()
UserForm1.Show
End Sub

Sub ShowUF2()
UserForm2.Show
End Sub

Sub DeleteMenu()
CommandBars("UserForms").Delete
End Sub

Of course, you will need to add error handling. Also, you can avoid writing
10 separate subs for the 10 forms but it requires quite a bit of effort.

--

Vasant

"Hank Hendrix" wrote in message
...
I have about 10 user forms. How can I create a new menu to select a user
form. The user forms contain prepared statements for use in a given area
(i.e. electrical, plumbing, grounds, etc)
The menu should be available only for this workbook.

Thanks
Hank




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Menu for user forms

Suggested amendment

Set UFBar = CommandBars.Add("UserForms")

to

Set UFBar = CommandBars.Add("UserForms", temporary:=True)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
This is pretty crude but should give you some ideas. CreateMenu should be
called from the Workbook_Activate event and DeleteMenu from the
Workbook_Deactivate event.

Sub CreateMenu()
Dim UFBar As CommandBar
Dim newButton As CommandBarButton
Set UFBar = CommandBars.Add("UserForms")
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm1"
.OnAction = "ShowUF1"
End With
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm2"
.OnAction = "ShowUF2"
End With
UFBar.Visible = True
End Sub

Sub ShowUF1()
UserForm1.Show
End Sub

Sub ShowUF2()
UserForm2.Show
End Sub

Sub DeleteMenu()
CommandBars("UserForms").Delete
End Sub

Of course, you will need to add error handling. Also, you can avoid

writing
10 separate subs for the 10 forms but it requires quite a bit of effort.

--

Vasant

"Hank Hendrix" wrote in message
...
I have about 10 user forms. How can I create a new menu to select a

user
form. The user forms contain prepared statements for use in a given

area
(i.e. electrical, plumbing, grounds, etc)
The menu should be available only for this workbook.

Thanks
Hank






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Menu for user forms

Thanks, Bob!

Regards,

Vasant.

"Bob Phillips" wrote in message
...
Suggested amendment

Set UFBar = CommandBars.Add("UserForms")

to

Set UFBar = CommandBars.Add("UserForms", temporary:=True)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
This is pretty crude but should give you some ideas. CreateMenu should

be
called from the Workbook_Activate event and DeleteMenu from the
Workbook_Deactivate event.

Sub CreateMenu()
Dim UFBar As CommandBar
Dim newButton As CommandBarButton
Set UFBar = CommandBars.Add("UserForms")
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm1"
.OnAction = "ShowUF1"
End With
Set newButton = UFBar.Controls _
.Add
With newButton
.Style = msoButtonCaption
.Caption = "UserForm2"
.OnAction = "ShowUF2"
End With
UFBar.Visible = True
End Sub

Sub ShowUF1()
UserForm1.Show
End Sub

Sub ShowUF2()
UserForm2.Show
End Sub

Sub DeleteMenu()
CommandBars("UserForms").Delete
End Sub

Of course, you will need to add error handling. Also, you can avoid

writing
10 separate subs for the 10 forms but it requires quite a bit of effort.

--

Vasant

"Hank Hendrix" wrote in message
...
I have about 10 user forms. How can I create a new menu to select a

user
form. The user forms contain prepared statements for use in a given

area
(i.e. electrical, plumbing, grounds, etc)
The menu should be available only for this workbook.

Thanks
Hank








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Menu for user forms

This is the code i used, em, called from open this work book and close
this work book like the other chap said, i added i've stuck them in
the charts menu bar and the file menue bar, and i have charts in my
workbook, may not be relivent for you:

This code is orgianlly from J-walk, cant remeber if i have adapteit it
any.

Just another example really

Good Luck

Ross.


Public Sub AddMenuBars()

'delets if alreadg there, stops muilily menu if error occures ;-)
Call RemoveMenuBars

'Set up nu menu
Dim HelpMenu As CommandBarControl
Dim NewMenu As CommandBarPopup
Dim MenuItem As CommandBarControl
Dim Submenuitem As CommandBarButton

Set HelpMenu = CommandBars(1).FindControl(Id:=30010)

If HelpMenu Is Nothing Then
Set NewMenu = CommandBars(1).Controls _
.Add(Type:=msoControlPopup, Temporary:=True)
Else
Set NewMenu = CommandBars(1).Controls _
.Add(Type:=msoControlPopup, Befo=HelpMenu.Index,
Temporary:=True)
End If

NewMenu.Caption = "E&DCSM"


Set MenuItem = NewMenu.Controls.Add(Type:=msoControlButton)
With MenuItem
.Caption = "&Controls"
.FaceId = 1845
.OnAction = "OpenControlsForm"
End With

Set MenuItem = NewMenu.Controls.Add(Type:=msoControlButton)
With MenuItem
.Caption = "C&hart Options"
.FaceId = 433
.OnAction = "OpenChartsForm"
End With

End Sub

Public Sub RemoveChartsMenuBars()
On Error Resume Next
CommandBars(2).Controls("E&DCSM").Delete
End Sub

Public Sub RemoveMenuBars()
On Error Resume Next
CommandBars(1).Controls("E&DCSM").Delete
End Sub
Public Sub OpenControlsForm()
Dim wb As Workbook
Dim cs As Chart

For Each wb In Application.Workbooks
For Each cs In wb.Charts
If cs.Name = "DisSatLines" Then
wb.Activate
ActiveWindow.WindowState = xlMaximized
frmControls.Show
Else: End If
Next cs
Next wb

End Sub
Public Sub OpenChartsForm()
Dim wb As Workbook
Dim cs As Chart

For Each wb In Application.Workbooks
For Each cs In wb.Charts
If cs.Name = "DisSatLines" Then
wb.Activate
ActiveWindow.WindowState = xlMaximized
Charts("DisSatLines").Activate
Else: End If
Next cs
Next wb

End Sub

Public Sub OpenChartsForm1()
Dim wb As Workbook
Dim cs As Chart

For Each wb In Application.Workbooks
For Each cs In wb.Charts
If cs.Name = "DisSatLines" Then
wb.Activate
ActiveWindow.WindowState = xlMaximized
frmCharts.Show
Else: End If
Next cs
Next wb

End Sub


Public Sub AddChartMenuBars()
'delets if alreadg there, stops muilily bar if error occures ;-)
Call RemoveChartsMenuBars

'Set up nu menu
Dim HelpMenu As CommandBarControl
Dim NewMenu As CommandBarPopup
Dim MenuItem As CommandBarControl
Dim Submenuitem As CommandBarButton

Set HelpMenu = CommandBars(2).FindControl(Id:=30010) ' number for
charts menu bar

If HelpMenu Is Nothing Then
Set NewMenu = CommandBars(2).Controls _
.Add(Type:=msoControlPopup, Temporary:=True)
Else
Set NewMenu = CommandBars(2).Controls _
.Add(Type:=msoControlPopup, Befo=HelpMenu.Index,
Temporary:=True)
End If

NewMenu.Caption = "E&DCSM"


Set MenuItem = NewMenu.Controls.Add(Type:=msoControlButton)
With MenuItem
.Caption = "&Controls"
.FaceId = 1845
.OnAction = "OpenControlsForm"
End With

Set MenuItem = NewMenu.Controls.Add(Type:=msoControlButton)
With MenuItem
.Caption = "C&hart Options"
.FaceId = 433
.OnAction = "OpenChartsForm1"
End With

End Sub


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
User Forms Runner77 Excel Discussion (Misc queries) 1 January 12th 06 06:20 AM
user forms Runner77 Excel Discussion (Misc queries) 0 January 12th 06 04:31 AM
User forms eklarsen[_4_] Excel Programming 2 May 6th 04 06:09 PM
User forms Scott Excel Programming 4 April 18th 04 06:22 PM
User forms Candee[_2_] Excel Programming 2 September 12th 03 03:11 PM


All times are GMT +1. The time now is 10:08 AM.

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

About Us

"It's about Microsoft Excel"