Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Macro attached to New Menu item on toolbar

I custom created a New Menu on the toolbar. It has an Assigned Macro. The
issue is if the user opens the file with the toolbar Menu item and then saves
the file somewhere else then the Assigned Macro follows it to the newly saved
file and I want to hold the macro at the original file.

Thank you for your help,

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro attached to New Menu item on toolbar

Steven,

My customary advice it to create and destroy the commandbar through code
using the workbook's open
and close events. See below.

HTH,
Bernie
MS Excel MVP

In the workbook's Thisworkbook object code module, place the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
DeleteCommandbar
End Sub

Private Sub Workbook_Open()
CreateCommandbar
End Sub

In a regular code module, place the following:

Dim myBar As CommandBar
Dim myButton As CommandBarButton

Sub CreateCommandbar()

On Error Resume Next
DeleteCommandBar

Set myBar = Application.CommandBars.Add("My Bar")
With myBar
.Position = msoBarTop
.Visible = True
.Enabled = True
Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
With myButton
.Caption = "Hello"
.Style = msoButtonIcon
.FaceId = 137
.Enabled = True
.OnAction = "SayHello"
End With
End With

End Sub

Sub DeleteCommandBar()
'Delete the commandbar if it already exists
On Error Resume Next
Application.CommandBars("My Bar").Delete
End Sub

Sub SayHello()
MsgBox "Hello there"
End Sub

You can add as many buttons or other menu items as you like, and assign
whatever macros you want.


"Steven" wrote in message
...
I custom created a New Menu on the toolbar. It has an Assigned Macro. The
issue is if the user opens the file with the toolbar Menu item and then
saves
the file somewhere else then the Assigned Macro follows it to the newly
saved
file and I want to hold the macro at the original file.

Thank you for your help,

Steven



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 to create menu/toolbar item with picture? hstijnen Excel Programming 0 April 25th 07 01:42 PM
New menu item OnAction can't see macro? Ed Excel Programming 13 January 25th 05 11:27 PM
re-enabling macro under menu item jerry h Excel Programming 1 April 18th 04 12:14 AM
Macro to display a menu item - possible? TonyJeffs Excel Programming 3 November 16th 03 08:38 AM
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 12:00 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"