Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Docking a commandbar.

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
I have this code that creates a button, but it puts it on the top left hand corner of the screen. I'd like to dock it, but couldn't find the routine to do that... How does one do that?


Sub auto_open()

Dim myButtonBar As CommandBar
Dim myButton As CommandBarButton
Dim commandbarItem As CommandBar
Dim buttonBarAlreadyExists As Boolean
Set myButtonBar = CommandBars.Add

'Check if the morning star commandbar is already there and exit if it is.
For Each commandbarItem In CommandBars
If commandbarItem.Name = "myButtonBar" Then
Exit Sub
End If
Next commandbarItem

'Add the bar
With myButtonBar
.Name = "myButtonBar"
.Visible = True
.Top = 0
.Left = 0
End With

'Add the control a button
Set myButton = myButtonBar.Controls.Add(msoControlButton)

With myButton
'.FaceId = 300
.Style = msoButtonCaption
.OnAction = "LogInTo"
.Caption = "Log in to"
End With

End Sub


Thanks,

Chris
 
Chrissirhc,
This code should add your CommandBar to the same line as the "Database" bar.
Code:
...
With myButtonBar
    .Name = "myButtonBar"
    .Visible = True
    .Top = 0
    .Left = 0
    [b].RowIndex = Application.CommandBars("Database").RowIndex[/b]
End with
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I just randomly looked at the commandbars and they are all rowindex = 1....

And when I try the code the button does not show... :(

Any ideas?

I'm using Excel 2000 if that is material.
 
Chrissirhc,
I'm using Excel 2000 (SR-1), this is what I get for the Standard toolbar row index:
Code:
? Application.CommandBars("Standard").RowIndex
 29

I use this in a routine to create a new toolbar and it works fine, but now that I look at it I'm reminded that I had to play with the [tt].Left[/tt] property of the new command bar to get it to work right. Here is the chuck of code:
Code:
...
[navy]Set[/navy] cbWebForm = Application.CommandBars.Add("AutoWebForm", msoBarTop, , True)
[navy]With[/navy] cbWebForm
  .RowIndex = Application.CommandBars("Standard").RowIndex
  .Left = Application.CommandBars("Standard").Width
  .Visible = [navy]True[/navy]
[navy]End With[/navy]
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
To "dock", do you mean to set it's position such as the Standard toolbar is at the "top" of the Excel toolbar space? If so, check out the Position syntax of the Add syntax, most notably the msoBarTop position.

Here is a good reference:

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top