View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Todd Huttenstine[_2_] Todd Huttenstine[_2_] is offline
external usenet poster
 
Posts: 237
Default Saving button on all workbooks

The below code creates a button on the Worksheet Menu Bar
at the top and assigns the macro ImporrtData to it.

The problem is when I save the workbook and then reopen
it, the button is no longer there, nor is it there on any
other workbook I open. Is there a way I can save it there
permanently?


Sub testaddbutton()
Dim newMenu As CommandBarPopup
Dim ctrlPopUp As CommandBarControl
Dim ctrlButton As CommandBarControl
Dim nButtonPos
Dim nButtons
Dim lpszButtonName$

If MsgBox("Are you sure?", vbYesNo) = vbNo Then
Exit Sub
Else
End If

nButtonPos = 0
nButtons =
Application.CommandBars.ActiveMenuBar.Controls.Cou nt

' see if the button is already placed
If nButtons = 0 Then
For i = 1 To nButtons
lpszButtonName$ =
Application.CommandBars.ActiveMenuBar.Controls(i). Caption
If lpszButtonName$ = "Import Data" Then Exit Sub
Next
End If

Set newMenu = CommandBars("Worksheet Menu
Bar").Controls.Add(Type:=msoControlPopup, Temporary:=True)

newMenu.Caption = "Import Data"

Set ctrlPopUp = newMenu.Controls.Add
(Type:=msoControlPopup, ID:=1)
ctrlPopUp.Caption = "Please Select..."
Set ctrlButton = ctrlPopUp.Controls.Add
(Type:=msoControlButton, ID:=1)
ctrlButton.Caption = "Import Data..."
ctrlButton.Style = msoButtonCaption
ctrlButton.OnAction = "ImporrtData"

' This will add the Button Import Data to the Menu Bar
' Under this button will be a button called "Import
Data..."
' this button will run the macro called ImporrtData
End Sub


Thanks

Todd Huttenstine