Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default adding button for add-in

Hi,

This is the sort of code I use, without any problems:

Private Sub Workbook_Open()
'these three lines are necessary incase excel closed due
to an 'error e.g Dr Watson.
On Error Resume Next
Application.CommandBars("standard").Controls("Form at me").Delete
On Error GoTo 0

Set oCtl = Application.CommandBars("standard")

With oCtl.Controls.Add(msoControlButton)
.BeginGroup = True
.Caption = "Format me"
.OnAction = "Mymacro"
.FaceId = 527
End With

end sub

also I'd have:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'to delete the button when the workbook closes
On Error Resume Next
Application.CommandBars("standard").Controls("form at me").Delete
On Error GoTo 0

End Sub

Regards
J


"cg" wrote in message ...
Hi all,

I created an add-in with the following code in it's open
event. My problem is this button is created everytime a
workbook is opened. yikes! Should I look for the button
before adding it and if so how? Is this the best way to
add a button for my macro in the add-in? Any help would
be greatly appreciated.

Private Sub Workbook_Open()

Dim oCtl As CommandBarControl
With Application.CommandBars("standard")
Set oCtl = .Controls.Add(Type:=msoControlButton)
With oCtl
.BeginGroup = True
.Caption = "Format me"
.OnAction = "Mymacro"
.FaceId = 527
End With
End With

End Sub

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
Adding a Button Bob Barnes Excel Discussion (Misc queries) 2 June 30th 08 07:36 PM
adding a button to a tool bar LenQ8 Excel Worksheet Functions 1 October 23rd 05 05:26 AM
Adding a button to a spreadsheet... PokerZan Excel Discussion (Misc queries) 4 July 22nd 05 12:50 AM
Adding Button to Tool Bar Jenn Excel Discussion (Misc queries) 6 February 23rd 05 09:33 PM
adding button for add-in Tom Ogilvy Excel Programming 1 October 1st 03 11:23 PM


All times are GMT +1. The time now is 07:31 PM.

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"