Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default CommandBars.Add problem

I am trying to create a toolbar with a button on it in the Workbook.Activate
event. Below is the code so far. I error out at the With TBar .Name line so I
don't know if anything else is wrong. Help would be greately appreciated.

Sub MakeToolbarBtn()
'
' Create new toolbar and button
Dim TBar As CommandBar
Dim NewBtn As CommandBarButton

Set TBar = CommandBars.Add
With TBar
.Name = "WWEnviro"
.Top = 0
.Left = 0
.Visible = True
End With

Set NewBtn = CommandBars("WWEnviro").Controls.Add _
(Type:=msoControlButton)
With NewBtn
.FaceId = 300
.OnAction = "FixIt"
.Caption = "FixFormatting"
End With
On Error Resume Next
'On Error GoTo 0

End Sub

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default CommandBars.Add problem

Hi Billy,

Something along these lines :

Set MyBar = CommandBars.Add(Name:="WWEnviro", _
Position:=msoBarFloating, temporary:=True)

With MyBar
.Top = 175
.Left = 650

etc ....

HTH
Cheers
Carim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default CommandBars.Add problem

Billy,

Check if the commandbar is already there and you're not trying to add a
commandbar with the same name? Run this procedure and check the result in
the Immediate window:

Public Sub CheckCommandBars()
Dim cmdBar As CommandBar
For Each cmdBar In Application.CommandBars
If cmdBar.Name = "WWEnviro" Then
Debug.Print "********************" & _
cmdBar.Name & "********************"
Else
Debug.Print cmdBar.Name
End If
Next cmdBar
End Sub

Have you got any code to remove the commandbar in a Workbook_Close event?
If not add this:

Public Sub RemoveCustomToolbar()
On Error Resume Next
CommandBars.("WWEnviro").Delete
End Sub


It's also worth adding a check in the MakeToolBar procedure to delete any
old instances left by a crash, so add:

Sub MakeToolbarBtn()

' Create new toolbar and button
Dim TBar As CommandBar
Dim NewBtn As CommandBarButton

On Error Resume Next
CommandBars.("WWEnviro").Delete
On Error GoTo 0


Hope that helps

Best regards

John



"Billy B" wrote in message
...
I am trying to create a toolbar with a button on it in the
Workbook.Activate
event. Below is the code so far. I error out at the With TBar .Name line
so I
don't know if anything else is wrong. Help would be greately appreciated.

Sub MakeToolbarBtn()
'
' Create new toolbar and button
Dim TBar As CommandBar
Dim NewBtn As CommandBarButton

Set TBar = CommandBars.Add
With TBar
.Name = "WWEnviro"
.Top = 0
.Left = 0
.Visible = True
End With

Set NewBtn = CommandBars("WWEnviro").Controls.Add _
(Type:=msoControlButton)
With NewBtn
.FaceId = 300
.OnAction = "FixIt"
.Caption = "FixFormatting"
End With
On Error Resume Next
'On Error GoTo 0

End Sub

Thank you



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
VBA problem with CommandBars zuEgg Excel Programming 5 July 28th 06 04:47 PM
commandbars in add-in Geoff Excel Programming 0 June 19th 06 09:28 PM
Commandbars dynamic menu creation problem GusEvans Excel Programming 6 April 6th 06 07:21 PM
CommandBars vs CommandBars(1).Controls Sean Excel Programming 3 April 3rd 06 01:34 PM
CommandBars garry Excel Programming 3 June 24th 04 03:12 PM


All times are GMT +1. The time now is 03:32 AM.

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"