I'm new to attaching macros to buttons.
What is the correct procedure to attach a macro to a button on a toolbar and have that button be available *only* for that workbook.
Thanks
Main Topics
Browse All TopicsI have created two macros and assigned them to two buttons on the toolbar in a workbook (#1).
I have created another excel worksheet with a different macro and assigned it to a button on the tool bar too.
The problem is that after I assigned the button in Workbook #2, the button for Worbook #1 disappear and I was left with the button for workbook #2.
How can I make individual buttons for individual workbooks and not have them afeect other workbooks?
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Could find out how to make new toolbars so I used this tip instead:
http://www.freelists.org/a
1) Open the View...Toolbars...Customiz
2) Click New
3) Type in a name for the toolbar (like totsubo1) on the popup window, then click OK. A toolbar will appear on your worksheet.
4) Click Attach, then select the toolbar from the popup window on left, and hit the Copy button to put it on your workbook, and click OK
5) Open the Commands tab and click on Macros
6) Drag a button face onto your toolbar
7) Click the Modify Selection button
8) Click Assign Macro from the popup window
9) Select one of your existing macros, then click OK
10) Click Close, then Save your workbook
totsubo,
A different technique (and simpler) is to attach a command button to your worksheet for each macro. To do this:
1) Open the View...Toolbars...Control Toolbox
2) Click the Triangle & Ruler icon on the upper left of the popup toolbar. You will now be in design mode.
3) Click on the Command Button icon, the fourth one down on the left
4) Click on your worksheet and hold the mouse button down to draw the command button on your worksheet
5) Double click on the command button to open its VBA code page and create a CommandButton1_Click sub
6) Call an existing macro or paste your code within this sub
7) If you want to change the button properties, click the Properties icon (top right) and then click your button.
8) Exit design mode by clicking the Triangle & Ruler icon once more
Now, when you click the button on your worksheet, it will run your macro.
Brad
The first solution you gave that rellies on toolbars is nice except that the new toolbar appears on all my workbooks, which I don't want.
The second solution you give is the one I provided in the link I gave :)
If you can tell me how to use toolbars and make sure the new toolbar only appears on the one workbook and no other workbook I'll happily give you the points :)
According to Chip Pearson, the new toolbar is stored in your *.xlb file. As we have both discovered, this makes the toolbar visible in all your workbooks. Clicking on the button will open the worksheet containing the macro linked to the button--at which point the macro will run. http://www.cpearson.com/ex
The benefit of attaching the toolbar to the workbook is so you can send it to other people.
The best solution will be creating the toolbar in VB add the code to the Workbook_Open, then delete or remove it in the Workbooks_Close...
I don't have any codes for toolbars though.. But I found a code that modifies the Menu bar... it places a new menu with submenus...
--------------------------
Sub Workbook_Open()
Dim cbMenuBar As CommandBar
Dim cbcustom As CommandBarPopup
Dim cbControl As CommandBarControl
Dim cbCustomBar As CommandBar
Dim cbMenuItem As CommandBarButton
Dim intCount As Integer
Dim strMenuInfo(1 To 8, 1 To 2) As String
Application.CommandBars("W
Set cbMenuBar = CommandBars("Worksheet Menu Bar")
Set cbcustom = cbMenuBar.Controls.Add(Typ
With cbcustom
.Tag = "OEE"
.Caption = "&OEE"
End With
strMenuInfo(1, 1) = "&Weekly"
strMenuInfo(1, 2) = "Getlastweek"
strMenuInfo(2, 1) = "&Daily"
strMenuInfo(2, 2) = "GetDailyYesterDay"
strMenuInfo(3, 1) = "&View TextFile"
strMenuInfo(3, 2) = "showText "
strMenuInfo(4, 1) = "&Update EQPT List"
strMenuInfo(4, 2) = "ShowPlanning"
strMenuInfo(5, 1) = "&Bactrack Weekly"
strMenuInfo(5, 2) = "ShowWeekly"
strMenuInfo(6, 1) = "&Daily Graphs"
strMenuInfo(6, 2) = "ShowDailyGraph"
For intCount = 1 To 6
Set cbControl = Application.CommandBars.Fi
msoControlPopup, Tag:="OEE")
Set cbCustomBar = cbControl.Control.CommandB
Set cbMenuItem = cbCustomBar.Controls.Add(T
With cbMenuItem
Select Case intCount
Case 3, 5, 6
.BeginGroup = True
End Select
.Caption = strMenuInfo(intCount, 1)
.OnAction = strMenuInfo(intCount, 2)
End With
Next
End Sub
--------------------------
__________________________
Private Sub Workbook_BeforeClose(Cance
Application.CommandBars("W
End Sub
--------------------------
This is just a suggestion though..
Hum ... I would have thought there would be a way to create a toolbar that stays with a workbook, and only with that one workbook.
I'll leave this question open a little longer and hope that someone can provide a simpler answer as to how to attach a toolbar to only one workbook. If not I'll give you the points.
I'm not really an expert in toolbars but I notice that it is imposible to attach a toolbar dedicated to one workbook only.. Actually I had been researching on how to that eversince I learned that I can make a userfriendly interface in Excel.
The attached toolbar is always present once the workbook is invoked, thus making it available all the time.
Business Accounts
Answer for Membership
by: byundtPosted on 2003-09-03 at 19:47:57ID: 9284700
Were the buttons attached to an existing toolbar, or to two new toolbars that were attached to the two workbooks?
The the buttons were on toolbars attached to the two workbooks (so you can share the workbooks and toolbars with other users), then the toolbars should have different names.