Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macros and Toolbar

I've created a set of a subroutines for a specific Excel file and an
associated toolbar.

All of the subroutines contained within this Excel file or any copy of
this file. Is there any way to make it so the associated toolbar is
only visible (or available) when one of these files are opened?

I know you can attach a toolbar to a file, but the toolbar remains
available even if I have another file open.

Is there any way to make it so that a toolbar moves with the Excel
file?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Macros and Toolbar

You could generate the toolbar dynamically, and create it on workbook open
and workbook activate, and delete it on workbook close and workbook
deactivate.



Private Sub Workbook_Open()
Call CreateMenu
End Sub

Private Sub Workbook_Activate()
Call CreateMenu
End Sub

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

Private Sub Workbook_DeActivate()
Call DeleteMenu
End Sub

Private Sub CreateMenu()
Dim oCb As CommandBar
Dim oCtl As CommandBarPopup
Dim oCtlBtn As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl.Caption = "myButton"
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro"
End With
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton2"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro2"
End With
'etc.
End With
End Sub

Private Sub DeleteMenu()

Dim oCb As CommandBar
On Error Resume Next
Set oCb = Application.CommandBars("Worksheet Menu Bar")
oCb.Controls("Tools").Controls("myButton").Delete
On Error GoTo 0
End Sub


'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"JJ" wrote in message
oups.com...
I've created a set of a subroutines for a specific Excel file and an
associated toolbar.

All of the subroutines contained within this Excel file or any copy of
this file. Is there any way to make it so the associated toolbar is
only visible (or available) when one of these files are opened?

I know you can attach a toolbar to a file, but the toolbar remains
available even if I have another file open.

Is there any way to make it so that a toolbar moves with the Excel
file?

Thanks!



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
Macros in Toolbar warburger Excel Programming 5 June 9th 06 07:15 AM
toolbar macros Ned Kelly Excel Discussion (Misc queries) 0 December 22nd 05 03:52 PM
Toolbar macros TMAC Excel Programming 4 September 17th 04 09:00 PM
Toolbar with Macros Mark Excel Programming 1 February 2nd 04 11:04 AM
Toolbar with Macros bw Excel Programming 4 July 31st 03 01:12 AM


All times are GMT +1. The time now is 06:17 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"