Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Open a form from Tool bar

I would like to create a button on the tool bar that will open a form. I
only want this button to appear on the tool bar when a particular workbook is
open.

Can this be done. If so, how?

Thanks

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Open a form from Tool bar

Hi
Put this code in your "ThisWorkbook" Module in the Visual Basic Editor
Private Sub Workbook_Activate()
Call Add_Menu
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Remove_Menu
End Sub

Private Sub Workbook_Deactivate()
Call Remove_Menu
End Sub

Private Sub Workbook_Open()
Call Add_Menu
End Sub

In a general Module put in the code

Public Sub Add_Menu()
Dim cbWSMenuBar 'Variable name for main Worksheet Menu Bar
Dim muCustom As CommandBarControl
Dim iHelpIndex As Integer 'item number of Help menubar item

Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
'If Excel crashed while last opened so that Before_Close() event
didn't happen
'the menubar may still exist. So delete it just in case
On Error Resume Next
cbWSMenuBar.Controls("Form Menu").Delete
On Error GoTo 0

iHelpIndex = cbWSMenuBar.Controls("Help").Index
Set muCustom = cbWSMenuBar.Controls.Add(Type:=msoControlPopup,
befo=iHelpIndex)

With muCustom
.Caption = "Form Menu"
With .Controls.Add(Type:=msoControlPopup)
With .Controls.Add(Type:=msoControlButton)
.Caption = "Form Input"
.OnAction = "Show_Userform"
End With
Set cbWSMenuBar = Nothing
Set muCustom = Nothing
End Sub

Public Sub Remove_RegisterMenu()
Dim cbWSMenuBar As CommandBar

On Error Resume Next 'Incase it has already been deleted
Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
cbWSMenuBar.Controls("Form Menu").Delete
Set cbWSMenuBar = Nothing
End Sub

The macro to call up your userform is called "Show_Userform" and
should again be in a general module.

regards
Paul

On Mar 8, 5:53 pm, "Fredriksson via OfficeKB.com" <u27002@uwe wrote:
I would like to create a button on the tool bar that will open a form. I
only want this button to appear on the tool bar when a particular workbook is
open.

Can this be done. If so, how?

Thanks

--
Message posted viahttp://www.officekb.com



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
how can i use form/skjema tool for meny list spred in dif arks NachOslo Excel Worksheet Functions 0 July 2nd 09 01:57 PM
how to keep the tool bar open Mark Setting up and Configuration of Excel 1 March 19th 08 07:04 PM
Using a template form, advance a form number everytime you open ShoDan Excel Discussion (Misc queries) 1 January 31st 08 01:34 PM
Worksheets open behind tool bars Larry Farwell Excel Discussion (Misc queries) 0 May 4th 05 06:48 PM
Is it possible to open the VBA form with a link in a sheet and to pass variable from a cell to the VBA form? Daniel[_14_] Excel Programming 1 August 29th 04 01:20 PM


All times are GMT +1. The time now is 06:35 PM.

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"