PDA

View Full Version : CommandBars: Top property



Howard Kaikow
06-15-2005, 11:20 PM
The problem described below occurs in Word 2003 and Word 2002, I've not recently tried in Word 2000 and Word 97.

Similar code does not have this problem in Excel 2003 or PowerPoint 2003.

For a CommandBar, the Top property means "For docked command bars, this property returns or sets the distance from the command bar to the top of the docking area".

Running the code below, two command bars are created, as desired, each on a separate row at the bottom of the window.

However, after saving and closing the template, both toolbars appear on the same row. This occurs whether or not I set the Left property to 0.

Anybody got an explanation?


Option Explicit


Private Sub CommandBarTop()
Dim cmdbar As office.CommandBar
Dim cmdbutton As office.CommandBarButton
Dim tmpActive As Word.Template
Dim intBeforeIndex As Integer
Dim lngCommandBarBottomHeight As Long

Set tmpActive = ActiveDocument.AttachedTemplate

CustomizationContext = MacroContainer

lngCommandBarBottomHeight = 0

Set cmdbar = CommandBars.Add(Name:="First", Position:=msoBarBottom, Temporary:=False, MenuBar:=False)
With cmdbar
.Visible = True
.Top = lngCommandBarBottomHeight
.Left = 0
lngCommandBarBottomHeight = lngCommandBarBottomHeight + .Height
End With

' Create controls for First command bar here
intBeforeIndex = 1
Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, Temporary:=False, Before:=intBeforeIndex, ID:=331)
With cmdbutton
.Style = msoButtonIcon
.FaceId = 106
.TooltipText = "DocClose"
End With

intBeforeIndex = intBeforeIndex + 1
Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, Temporary:=False, Before:=intBeforeIndex, ID:=141)
With cmdbutton
.Style = msoButtonIcon
.FaceId = 46
.TooltipText = "EditFind"
End With


Set cmdbar = CommandBars.Add(Name:="Second", Position:=msoBarBottom, Temporary:=False, MenuBar:=False)
With cmdbar
.Visible = True
.Top = lngCommandBarBottomHeight
.Left = 0
lngCommandBarBottomHeight = lngCommandBarBottomHeight + .Height
End With

' Create controls for Second command bar here

intBeforeIndex = 1
Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, Temporary:=False, Before:=intBeforeIndex, ID:=752)
With cmdbutton
.Style = msoButtonCaption
.Caption = "FileExit"
.TooltipText = "FileExit"
End With

intBeforeIndex = intBeforeIndex + 1
Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, Temporary:=False, Before:=intBeforeIndex, ID:=748)
With cmdbutton
.Style = msoButtonCaption
.Caption = "FileSaveAs"
.TooltipText = "FileSaveAs"
End With

intBeforeIndex = intBeforeIndex + 1
Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, Temporary:=False, Before:=intBeforeIndex, ID:=37)
With cmdbutton
.TooltipText = "EditRepeat"
End With

tmpActive.Save

Set tmpActive = Nothing
Set cmdbar = Nothing
Set cmdbutton = Nothing
End Sub

Howard Kaikow
06-16-2005, 08:27 AM
It's been suggested that 3rd party software may cause this problem.

I rebooted to a system with Office 2000.
The problem did not occur using Word 2000.

However, this is not ceteris paribus.
The Office 2000 system has Acrobat 4 and NAV 2003, the Office 2003 system has Acrobat 5 and NAV 2004.
The Office 2003 system has Omni Page Pro Office 14, the other does not.
Etc.

I guess I have to write this issue off to the effect of some 3rd party
software.

P.S. Same problem occurs if I use msoBarTop.

Howard Kaikow
06-16-2005, 10:17 AM
I found an odd workaround, which implies that the problem is with Word, not with any 3rd party software.

Originally, I was creating a toolbar with several msoControlButton controls.

If I instead did the following, then the toolbar placement is correct.

Instead of directly placing the button controls on the toolbar, I put a single popup control on the toolbar and then placed the buttons on that single popup control.

Why the latter would cause proper toolbar placement and not the former is beyond my comprehension.
Do not see how 3rd party software could be the issue.

This makes no sense (to me).

Howard Kaikow
06-16-2005, 11:38 AM
I spoke too soon.

Problem came back.

Uncle!

MOS MASTER
06-16-2005, 12:52 PM
Hi Howard, :yes

I can confirm there is no problem in 97 and 2000.
The toolbar position is retained during open and close.

I also have this issue in 2002 and 2003!

But consider the following.
If you have those 2 toolbars in 97 or 2000 and you shift them manualy in to the right place and then close and open the document..the position will be retained. Fact: it works by Interface and by code.

However doing the same thing in 2002 and 2003 it simply doesn't retain the position if you've shift the toobars by hand.

So 2 things could be the problem. It's a bug that's inhereted from 2002 to 2003 (Both have it)

Or Word deals with toolbars differently then in previous versions <2002
The fact is that you can't do it by hand in those versions so its not surprising it isn't retained doing it by code!

To me this means you have to check for the application version and if <2002 do the positioning of the toolbars in the open or new event!

Later..:whistle:

Howard Kaikow
06-16-2005, 01:12 PM
I spoke too soon.

Problem came back.

Uncle!

Well, I again spoke too soon!
Problem has gone away!

Aunt!!!!

MOS MASTER
06-16-2005, 01:19 PM
Well, I again spoke too soon!
Problem has gone away!

Aunt!!!!
Could you post your new code so I can confirm? :whistle:

Howard Kaikow
06-16-2005, 01:29 PM
Hi Howard, :yes

I can confirm there is no problem in 97 and 2000.
The toolbar position is retained during open and close.

I also have this issue in 2002 and 2003!

Well, misery loves company, so you've made me happy!


But consider the following.
If you have those 2 toolbars in 97 or 2000 and you shift them manualy in to the right place and then close and open the document..the position will be retained. Fact: it works by Interface and by code.

However doing the same thing in 2002 and 2003 it simply doesn't retain the position if you've shift the toobars by hand.

There's no problem if I move the toolbars manually, so I guess I'm not as miserable as you.


To me this means you have to check for the application version and if <2002 do the positioning of the toolbars in the open or new event!

I'm not sure that would solve the problem.

If I stare at the screen while Word is starting, the toolbar(s) get put in the right position, but then are quickly moved.

The implication is that there's a bug in Word, or some 3rd party or auto macro is messing things up.

The only toolbar stuff I had in my own Auto macros was to make sure that 3 were visible. I pulled that code, but it made no difference.

Most interestingly, AFTER I reported above that the problem had gone away, I made the code more efficient. However, I left in a duplicate line so I ended up with a blank entry between each control on the pop-up menu, but that should not cause a problem. Yet, that did trigger the incorrect placement of the toolbar. I then removed the empty controls and, as of a few minutes ago, the toolbar was being placed correctly.

I find it hard to believe that the content of the toolbar is in any way related to this problem.

I do recall that a number of years ago, Acrobat caused a problem with toolbar placement. I have Acrobat 5 and most of the Acrobat code for Word is in a DLL so I cannot look at it.

MOS MASTER
06-16-2005, 01:44 PM
Well, misery loves company, so you've made me happy!
Always loved a good mis(er)(to)ry! :yes


There's no problem if I move the toolbars manually, so I guess I'm not as miserable as you.
Really? well that's funny.
I've tried this on 2 pc's running 2002 both did what you described. Open ok and in a blink of an eye they where aligned next to each other.
One machine has mucho programs the other one is a blank XP SP1 machine with Office XP Sp3

On my laptop running 2003 it also doesn't work. (Retain the position)

Again 97 and 2000 no problems. Both retain just fine.

I higly doubt a third party app is bugging you and me but I will examine my machines as well.

Again please post your new code which seams to work for you so I can help you try it. :whistle:

MOS MASTER
06-16-2005, 01:48 PM
I do recall that a number of years ago, Acrobat caused a problem with toolbar placement. I have Acrobat 5 and most of the Acrobat code for Word is in a DLL so I cannot look at it.
Well I don't have Acrobat installed and thus haven't got that addin. (I have it at work and I no the problems it can cause)

Another troublesome critter is the Office-plugin of NAV I've allready shut that one down. (By the way the clean machine doesn't have NAV)

I've looked for addins that where loaded and shut them all down..Problem stays...:whistle:

Howard Kaikow
06-16-2005, 02:09 PM
i have no new code to post.

the changes i made were in my real app.
the problem persists with the sample code i posted.

in my real app, instead of creating separate buttons on the toolbar, I placed a pop-up on the toolbar and added the buttons to the pop-up. This seems to have eliminated the problem, but that makes no sense.

MOS MASTER
06-16-2005, 02:22 PM
No indeed that doesn't..

Well I'll try some variations on your code later to see if I can make the critters stick...but to me it's fault by design >2002...

We'll see...:whistle:

sandam
06-17-2005, 01:01 AM
I think that the acrobat toolbar may be interfering with your sample code. I have a toolbar I create on AutoNew for some templates. It works fine on most people's PC's at work except the one secretary with Adobe Prof. 6. Even though i the code I eplicitly set the toolbar to visible, it never appears, she has to use view->toolbars. Thus I have come to the conclusion that it is either the interference of the Adobe DLL with Word's toolbars. Or that there are inherent flaws in Word's toolbars made all the more known by this and your example. ot that its a bad thing. I think its just annoying more than anything else.

Andrew;?

Howard Kaikow
06-17-2005, 08:10 AM
I think that the acrobat toolbar may be interfering with your sample code. I have a toolbar I create on AutoNew for some templates. It works fine on most people's PC's at work except the one secretary with Adobe Prof. 6. Even though i the code I eplicitly set the toolbar to visible, it never appears, she has to use view->toolbars. Thus I have come to the conclusion that it is either the interference of the Adobe DLL with Word's toolbars. Or that there are inherent flaws in Word's toolbars made all the more known by this and your example. ot that its a bad thing. I think its just annoying more than anything else.

Andrew;?

In earlier versions of Acrobat, I was able to look at the code they used for the PDFWriter crap. They did move stuff around.

However, those toolbars are at the top, and I am placing this toolbar at the bottom.

In addition, since my main system has Office 2003, Acrobat 5 won't install PDFWriter.dot for Office 2003.

Other possibilities are 3rd party apps such as Omni Page Pro Office 14. Last year, I peaked at the code they use and they are doing something stupid in their AutoClose that causes Normal.dot to change. They might have other stupidities in their AutoExec, etc. macros, if any such macros are used.

You can clearly see that the toolbar(s) are correctly positioned as soon as Word starts, but then are quickly moved. I would suspect that the movement is caused by an obscure bug in Word.

The only toolbar stuff I had in my Auto macros was code to make sure that 3 of my custom toolbars are visible. I removed that code.

A solution would likely be to add code to AutoExec. AutoOpen and AutoNew to forece repositioning, but that only works locally.

I am giving the user a choice of installing a toolbar at the top or at the bottom. Once installed, it's up to the user where they want to move it. If I force repositioning with an Auto macro, then users will not be able to reposition.

The really odd thing is that in my real app, if I create the toolbar with a single pop-up button, instead of separate buttons for each option, then the toolbar postions correctly. This would seem to indicate that it is a Word problem, as I would not expect 3rd party software's behavior to change based on the structure of my toolbar.

This thread should likely be marked "NEVER To Be Solved".

sandam
06-17-2005, 08:27 AM
This thread should likely be marked "NEVER To Be Solved".

True. I must point out that our firm uses Office 2003 as to the repositioning etc. I think you may have hit the nail on the head with it being an obscure bug in Word. Ah well.:think:

Andrew;?

MOS MASTER
06-18-2005, 11:00 AM
Hi,

I've also did a test with the commandbarpopup and then the buttons on top of that one.

That also solved the problem here partialy.

My drawing toolbar is always the only toolbar that sits in the bottom if I run your code adjusted with the popup controls all three toolbars are stacked to the bottom Drawing on top.

If I close and reopen yours will still be in the right place and the Drawing toolbar is shifted to the right of your top toolbar..

Conclusion....This is like I said before a WORD problem with version 2002/2003. I don't use any thirdparty apps and I'm receiving the problems aswell so...

Later..:whistle: