A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Need help with adjusting width of VBA-created toolbars



 
 
Thread Tools Display Modes
  #1  
Old February 10th, 2004, 04:45 PM
Mark Reynolds
external usenet poster
 
Posts: n/a
Default Need help with adjusting width of VBA-created toolbars

Hello,
I am using VBA to create a series of toolbars, which are then assigned
to macros. The problem I am having is:
If I create a toolbar manually, it automatically adjusts its width to
whatever caption is specified. However, when I create a toolbar with
VBA, the width does not adjust itself to the caption, so the toolbar
is wider than neccessary. Here is an example of the code I am using:

Sub newButton3()
On Error Resume Next
CommandBars("C").Delete
Dim cBar, ccBar
CommandBars.Add.Name = "C"
Set cBar = CommandBars("C")
Set ccBar = CommandBars("C").Controls.Add(Type:=msoControlButt on)

With cBar
.Visible = True
.Left = 945
.Top = 260
.Controls.Add Type:=msoControlButton
.Controls(1).Caption = "UserSetIT"
.Controls(1).OnAction = _
"'C:\IFR Macros\MacroBank.xls'!UserSetit"
End With

With ccBar
.Style = msoButtonCaption
.TooltipText = "Allows User to Set CF and Span"
End With

End Sub

Any pointers/suggestions would be greatly appreciated. Thanks for any
help.

Mark
  #2  
Old February 10th, 2004, 05:47 PM
Bernie Deitrick
external usenet poster
 
Posts: n/a
Default Need help with adjusting width of VBA-created toolbars

Mark,

Your code worked fine for me.... Changing the caption text resulted in
different width toolbars each time the code was run.

HTH,
Bernie
MS Excel MVP


"Mark Reynolds" wrote in message
...
Hello,
I am using VBA to create a series of toolbars, which are then assigned
to macros. The problem I am having is:
If I create a toolbar manually, it automatically adjusts its width to
whatever caption is specified. However, when I create a toolbar with
VBA, the width does not adjust itself to the caption, so the toolbar
is wider than neccessary. Here is an example of the code I am using:

Sub newButton3()
On Error Resume Next
CommandBars("C").Delete
Dim cBar, ccBar
CommandBars.Add.Name = "C"
Set cBar = CommandBars("C")
Set ccBar = CommandBars("C").Controls.Add(Type:=msoControlButt on)

With cBar
.Visible = True
.Left = 945
.Top = 260
.Controls.Add Type:=msoControlButton
.Controls(1).Caption = "UserSetIT"
.Controls(1).OnAction = _
"'C:\IFR Macros\MacroBank.xls'!UserSetit"
End With

With ccBar
.Style = msoButtonCaption
.TooltipText = "Allows User to Set CF and Span"
End With

End Sub

Any pointers/suggestions would be greatly appreciated. Thanks for any
help.

Mark



  #3  
Old February 11th, 2004, 02:24 AM
Mark Reynolds
external usenet poster
 
Posts: n/a
Default Need help with adjusting width of VBA-created toolbars

Thanks Bernie,
After reading your response I tried my macro again and discovered you
were right: The toolbar width was automatically adjusting to the
caption. What had fooled me was the fact that the toolbar was coming
out a little wider than neccessary, causing extra space after the
caption. I fooled around some more and took care of this problem by
removing the following line of code:

.Controls.Add Type:=msoControlButton

Thanks for helping lead me to this fix.

Mark
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.