PC Review


Reply
Thread Tools Rate Thread

Add button to commandbar to all workbooks within xla

 
 
Franck
Guest
Posts: n/a
 
      4th Oct 2005
Hi,
Is it possible, within my xla, to create a new button in an existing
commandbar whenever Excel is open ?

Thks for help

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      4th Oct 2005
One way:

Option Explicit
Sub auto_open()

Dim myCMDBar As CommandBar
Dim myNewCtrl As CommandBarControl

Set myCMDBar = Application.CommandBars("formatting")

On Error Resume Next
myCMDBar.Controls("my New Item").Delete
On Error GoTo 0

Set myNewCtrl = Application.CommandBars("formatting").Controls.Add _
(Type:=msoControlButton, temporary:=True)

With myNewCtrl
.Caption = "my New Item"
.OnAction = ThisWorkbook.Name & "!" & "mynewitemmacro"
.Visible = True
.BeginGroup = True
.FaceId = 232
End With

End Sub
Sub auto_close()
On Error Resume Next
myCMDBar.Controls("my New Item").Delete
On Error GoTo 0
End Sub
Sub myNewItemMacro()
MsgBox "hi from my new item"
End Sub

If you're looking for nice icons:

John Walkenbach has a FaceId identifier program at:
http://j-walk.com/ss/excel/tips/tip67.htm

Jim Rech has one at:
http://www.oaltd.co.uk/MVP/MVPPage.asp#JimRech

Franck wrote:
>
> Hi,
> Is it possible, within my xla, to create a new button in an existing
> commandbar whenever Excel is open ?
>
> Thks for help


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Oct 2005
Change the auto_close code to:


Sub auto_close()
Dim myCMDBar As CommandBar
Set myCMDBar = Application.CommandBars("formatting")
On Error Resume Next
myCMDBar.Controls("my New Item").Delete
On Error GoTo 0
End Sub



Dave Peterson wrote:
>
> One way:
>
> Option Explicit
> Sub auto_open()
>
> Dim myCMDBar As CommandBar
> Dim myNewCtrl As CommandBarControl
>
> Set myCMDBar = Application.CommandBars("formatting")
>
> On Error Resume Next
> myCMDBar.Controls("my New Item").Delete
> On Error GoTo 0
>
> Set myNewCtrl = Application.CommandBars("formatting").Controls.Add _
> (Type:=msoControlButton, temporary:=True)
>
> With myNewCtrl
> .Caption = "my New Item"
> .OnAction = ThisWorkbook.Name & "!" & "mynewitemmacro"
> .Visible = True
> .BeginGroup = True
> .FaceId = 232
> End With
>
> End Sub
> Sub auto_close()
> On Error Resume Next
> myCMDBar.Controls("my New Item").Delete
> On Error GoTo 0
> End Sub
> Sub myNewItemMacro()
> MsgBox "hi from my new item"
> End Sub
>
> If you're looking for nice icons:
>
> John Walkenbach has a FaceId identifier program at:
> http://j-walk.com/ss/excel/tips/tip67.htm
>
> Jim Rech has one at:
> http://www.oaltd.co.uk/MVP/MVPPage.asp#JimRech
>
> Franck wrote:
> >
> > Hi,
> > Is it possible, within my xla, to create a new button in an existing
> > commandbar whenever Excel is open ?
> >
> > Thks for help

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Franck
Guest
Posts: n/a
 
      6th Oct 2005
Works great ! Thks ^^

Dave Peterson wrote:
> Change the auto_close code to:
>
>
> Sub auto_close()
> Dim myCMDBar As CommandBar
> Set myCMDBar = Application.CommandBars("formatting")
> On Error Resume Next
> myCMDBar.Controls("my New Item").Delete
> On Error GoTo 0
> End Sub
>
>
>
> Dave Peterson wrote:
> >
> > One way:
> >
> > Option Explicit
> > Sub auto_open()
> >
> > Dim myCMDBar As CommandBar
> > Dim myNewCtrl As CommandBarControl
> >
> > Set myCMDBar = Application.CommandBars("formatting")
> >
> > On Error Resume Next
> > myCMDBar.Controls("my New Item").Delete
> > On Error GoTo 0
> >
> > Set myNewCtrl = Application.CommandBars("formatting").Controls.Add _
> > (Type:=msoControlButton, temporary:=True)
> >
> > With myNewCtrl
> > .Caption = "my New Item"
> > .OnAction = ThisWorkbook.Name & "!" & "mynewitemmacro"
> > .Visible = True
> > .BeginGroup = True
> > .FaceId = 232
> > End With
> >
> > End Sub
> > Sub auto_close()
> > On Error Resume Next
> > myCMDBar.Controls("my New Item").Delete
> > On Error GoTo 0
> > End Sub
> > Sub myNewItemMacro()
> > MsgBox "hi from my new item"
> > End Sub
> >
> > If you're looking for nice icons:
> >
> > John Walkenbach has a FaceId identifier program at:
> > http://j-walk.com/ss/excel/tips/tip67.htm
> >
> > Jim Rech has one at:
> > http://www.oaltd.co.uk/MVP/MVPPage.asp#JimRech
> >
> > Franck wrote:
> > >
> > > Hi,
> > > Is it possible, within my xla, to create a new button in an existing
> > > commandbar whenever Excel is open ?
> > >
> > > Thks for help

> >
> > --
> >
> > Dave Peterson

>
> --
>
> Dave Peterson


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uh-oh, unexpected behaviour. Commandbar shows up in all workbooks and doesn't close down. StargateFanFromWork Microsoft Excel Programming 6 9th Dec 2005 05:11 PM
CommandBar Button parameters Bill D. Microsoft Excel Programming 3 26th Mar 2004 07:13 PM
CommandBar Button pictures Vyyk Drago Microsoft Outlook VBA Programming 1 4th Mar 2004 06:54 PM
CommandBar button events Stee Microsoft Powerpoint 0 7th Jan 2004 01:46 PM
Add an image to a commandbar button Marc Microsoft Outlook Program Addins 3 27th Nov 2003 10:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.