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

Private Sub Workbook_Open()

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

End Sub

--
Regards,
Tom Ogilvy


"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



  #2   Report Post  
Posted to microsoft.public.excel.programming
cg cg is offline
external usenet poster
 
Posts: 6
Default adding button for add-in

Thanks again Tom, I can always count on you to save my
day!
-----Original Message-----
Private Sub Workbook_Open()

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

End Sub

--
Regards,
Tom Ogilvy


"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 PRINT CONTROL BUTTON Tonya Excel Worksheet Functions 1 September 25th 06 09:55 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


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