Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jon jon is offline
external usenet poster
 
Posts: 18
Default Toolbar button To Run a Macro?

I have a load of macros to compress data into a standard
form, and one macro to run them all sequentially.
I don't really want a button in the worksheet itself, so
I was wondering if there is any way of making a button in
a toolbar which will start the macro up?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Toolbar button To Run a Macro?

Hi jon,

you can paste the following code into "This Workbook":

Private Sub Workbook_Open()

Dim cBar As CommandBar
Dim cCtl As Object
Dim nCtl As Object
Dim MnuPopup As CommandBarPopup
Dim BtnButton As CommandBarButton

For Each cCtl In Application.CommandBars("Worksheet
Menu Bar").Controls
If (cCtl.Caption = "Dead Stock Report") Then
Exit For
End If
Next cCtl
If (cCtl Is Nothing) Then
Set MnuPopup = Application.CommandBars("Worksheet
Menu Bar").Controls.Add(Type:=msoControlPopup,
Temporary:=True)
MnuPopup.Caption = "Dead Stock Report"
Set cCtl = MnuPopup
End If
For Each nCtl In cCtl.Controls
If ((nCtl.Caption = "Create Report From Raw Data")
Or _
(nCtl.Caption = "Merge New Retail Prices") Or _
(nCtl.Caption = "Create Store Workbooks") Or _
(nCtl.Caption = "Add Stock Differences")) _
Then
nCtl.Delete
End If
Next nCtl
Set BtnButton = cCtl.Controls.Add
(Type:=msoControlButton, Temporary:=True)
BtnButton.Caption = "Create Report From Raw Data"
BtnButton.OnAction = "MakeDeadStockReport"
Set BtnButton = cCtl.Controls.Add
(Type:=msoControlButton, Temporary:=True)
BtnButton.Caption = "Merge New Retail Prices"
BtnButton.OnAction = "MergeNewPrices"
Set BtnButton = cCtl.Controls.Add
(Type:=msoControlButton, Temporary:=True)
BtnButton.Caption = "Create Store Workbooks"
BtnButton.OnAction = "CreateStoreWorkbooks"
Set BtnButton = cCtl.Controls.Add
(Type:=msoControlButton, Temporary:=True)
BtnButton.Caption = "Add Stock Differences"
BtnButton.OnAction = "AddStockDifferences"

End Sub

The code will be activated when the workbook is open and
will add a PopUp labeled "Dead Stock Report" to the Excel
command bar. Then 4 buttons labeled "Create Report From
Raw Data", "Merge New Retail Prices", "Create Store
Workbooks", and "Add Stock Differences" are added to the
popup.

The OnAction property of each button must contain the name
of a public sub located within a module that will perform
the action.

Have fun...

Peter


-----Original Message-----
I have a load of macros to compress data into a standard
form, and one macro to run them all sequentially.
I don't really want a button in the worksheet itself, so
I was wondering if there is any way of making a button in
a toolbar which will start the macro up?

.

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
Save a macro button onto a toolbar BG Mark Excel Discussion (Misc queries) 7 June 5th 10 05:44 PM
Macro button on toolbar Daniel Charts and Charting in Excel 0 August 27th 07 08:56 PM
Button with macro in toolbar Daniel Charts and Charting in Excel 1 August 25th 07 02:39 AM
Macro button on toolbar Lesley Excel Discussion (Misc queries) 2 August 28th 06 07:32 PM
MACRO ATTACHED TO A TOOLBAR BUTTON Joyce[_2_] Excel Programming 0 October 9th 03 07:30 PM


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