Add-ins tab not displayed when "Show all windows in taskbar" is of

J

Julian Ladbury

I have an application which dynamically adds a toolbar to documents opened in
versions up to and including 2003. A separate toolbar is added to each
document ("CustomizationContext = ThisDocument"). In 2007, it works fine
except when option "Advanced > Display > Show all windows in taskbar" is off.
In that case, the first document I open puts the toolbar on the Addins tab as
expected. The second does not - no Addins tab is displayed, let alone my
toolbar.

If I switch back to doc1, the Addins tab is still there and includes my
toolbar. Switching back to doc2, the Addins tab appears, but when I click on
it it disappears.

When "Advanced > Display > Show all windows in taskbar" is ticked, I have no
problems - the Addins tab appears and works properly in both docs.

In my application the problem occurs 100% of the time. I have produced a
cut-down test file to investigate and demonstrate the problem: in that, it
occurs intermittently.
 
W

Wei Lu [MSFT]

Hello J,

I would like to get more detailed information of your add-in so that I can
try to reproduce this issue in my side.

Did you use a VB COM addin? Could you please let me know the test code you
use?

Also, please let me know the OS version.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Julian Ladbury

I have got to the bottom of the problem.

Firstly, let me say that my earlier statement that my 'cut-down' test files
showed the problem intermittently was probably wrong - today they would not
demonstrate the problem at all. However, with further investigation I can now
reproduce the problem to order.

Next - to answer Wei-Lu, my addin is not a COM one, but a VBA one.

Now to what I think is the the root of the problem. My program uses the VBA
function below to determine whether a named toolbar exists, and if it does
not it adds it;

Public Function BWordToolbarExists(xName As String, xDoc As Document) As
Boolean
Dim out As Boolean
Dim tb As CommandBar
out = False
For Each tb In xDoc.CommandBars
If tb.Name = xName Then
out = True
Exit For
End If
Next tb
BWordToolbarExists = out
End Function

Now, if I open two documents running this code, both looking for the
existence of an identically-named toolbar, the function returns 'True' when
option Advanced > Display > Show all windows in taskbar is off, but False if
it is on.

My conclusion is that this might be a Word 2007 bug, described like this:

Iteration through a Document.CommandBars collection returns different
results depending on the Advanced > Display > Show all windows in taskbar
setting.

If anyone is interested, I have set this out in more detail in a Word
document which also contains VBA code and instructions to reproduce the
problem.
 
J

Julian Ladbury

Just to clarify my earlier reply, it is when the code executes in the second
of two documents that it can retutn True. Executing in the second document
opened alwayd returns False.
 
J

Julian Ladbury

Aargh, finger trouble and haste! Please ignore my previous 'clarification'
which should have read:
 
W

Wei Lu [MSFT]

Hello,

I will do some further research on this. If I get any progress, I will
inform your ASAP.


Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Julian Ladbury

Wei Lu - Would you like me to send you the document which reproduces the
problem? If so, let me know where to send it.
 
J

Julian Ladbury

Further investigation shows that this behaviour is not unique to Word 2007 (I
have just reproduced it in 2003). I will not go into the tedious reasons that
led me to believe it was, and apologise for any inconvenience I may have
caused.

I would now characterise the problem as follows:

Setting the CustomizationContext to a particular document (eg ThisDocument)
when adding a toolbar suggests to the suggestible programmer that when
iterating though ThisDocument.CommandBars you could potentially find a
different set of toolbars to those in 'AnotherDocument'.CommandBars. However,
when Application.ShowWindowsInTaskbar = True, the Document.CommandBars
collection seems to ignore the CustomizationContext and includes ALL command
bars in ALL open documents.

This behaviour might be intended: I have seen
'Application.ShowWindowsInTaskbar = True' described as presenting a 'Single
Document Interface', which this behaviour would fit. If it is indeed
intended, it could be worth updating the documentation somewhere to warn
others of this pitfall.
 
J

Jialiang Ge [MSFT]

Hello Julian,

Thank you for your patience, I reproduced your issue and find that

1 when the CustomizationContext is set to this document (as you mentioned)
and ShowWindowsInTasks is False, An exception is thrown when I open the 2nd
word document and click the addin (the error code is 2147467259, the error
message is Error HRESULT E_FAIL has been returned from a call to a COM
component, and it takes place in a call to "Visible=True" in my test code),
The error code 2147467259 means "the callee (server [not server
application]) is not available, and disappeared; all connections are
invalid. The call did not execute."

2.when CustomizationContext is not set and ShowWindowsInTasks is False, no
error occurs and everything is fine.

You once mentioned that you'd like to send me your document which
reproduces the problem. Would you email it to me so that I can confirm both
our test codes are in the same scenario and I will do some further research
on it.

Have a nice day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Julian Ladbury

Jialiang,

I have sent you a copy of my test document. I suspect we are not testing
exactly the same scenario, as I do not get any exception - though it could be
that one is hidden and handled by the time the low level code gets back up to
my VBA call.

Let me know how it goes!

Thanks,
Julian
 
J

Jialiang Ge [MSFT]

Hello Julian,

I've received you sample. It's pretty cool!! :)
In order to share the information in this community, I'd paste you
document's content here if you do not mind.
Here is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.

----------------------------------------------------------------------------
----------------------
Background
ChronoLator is a Word application written in VBA. It adds a toolbar to a
Word document when it opens. (In Word 2007, this is added to the Add-ins
tab).
If the Show Windows in Taskbar option is off and you open two ChronoLator
documents, only the first one displays a toolbar (in 2007, no Add-Ins tab
appears). If it is on, both do.
This behaviour was first discovered when testing Word 2007, but is also
reproducible in XP & 2003.

Investigation
Investigation showed that the cause is that the function BWordToolbarExists
returns True in the first case, False in the latter. This is because of
this line of code in the procedure which adds the toolbar:
If BWordToolbarExists(c8Name, ThisDocument) Then Exit Function
' can happen if user is impatient and tries to open document twice from
Explorer

Reproduction
This document can be used to illustrate the root cause of the problem as
follows:
1. Make a copy of this document;
2. Set Show Windows in Taskbar off;
3. Open this document:
4. Open the copy:
5. Open the VBA IDE and look at the Immediate window. It will show
something like:
Bug12 addins tab.doc: False
Copy of Bug12 addins tab.doc: True
6. Close both documents.
7. Set Show Windows in Taskbar on;
8. Open this document:
9. Open the copy:
10. Open the VBA IDE and look at the Immediate window. It will show
something like:
Bug12 addins tab.doc: False
Copy of Bug12 addins tab.doc: False

Root cause - a Word bug / documentation requirement?
It is reasonable to expect that setting the CustomizationContext to a
particular document (eg ThisDocument) when adding a toolbar would mean that
when iterating though ThisDocument.CommandBars you could potentially find a
different set of toolbars to those in 'AnotherDocument'.CommandBars.
However, when Application.ShowWindowsInTaskbar = True, the
Document.CommandBars collection seems to ignore the CustomizationContext
and includes ALL command bars in ALL open documents.
It seems unlikely that this behaviour is intended - there is no obvious
link between CustomizationContext and the ShowWindowsInTaskbar option, and
this looks like an undesired side-effect. However, if it is intended it
should be documented somewhere - probably under the CommandBars
documentation.

VBA code in this document
Public Sub AutoOpen()
Dim myToolbar As CommandBar
Dim myButton As CommandBarButton
CustomizationContext = ActiveDocument

Debug.Print ThisDocument.Name & ": " & BWordToolbarExists("testTB",
ThisDocument)
Set myToolbar = CommandBars.Add("testTB", msoBarTop, False, True)
Set myButton = myToolbar.Controls.Add(msoControlButton)
With myButton
.FaceId = 161
.Style = msoButtonIconAndCaption
.Caption = "myButtonCaption"
.TooltipText = "myButtonToolTip"
.OnAction = "myButtonAction"
End With
myToolbar.Visible = True
ThisDocument.Saved = True 'adding bars dirties the doc
End Sub
Sub myButtonAction()
MsgBox "Executing in document <" & ThisDocument.Name & "> "
End Sub
Public Function BWordToolbarExists(xName As String, xDoc As Document) As
Boolean
Dim out As Boolean
Dim tb As CommandBar
out = False
For Each tb In xDoc.CommandBars
If tb.Name = xName Then
out = True
Exit For
End If
Next tb
BWordToolbarExists = out
End Function
----------------------------------------------------------------------------
----------------------

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Julian Ladbury

I have one small, but highly significant to the text of the test document
below. A replacement of 'True' by 'False' no less . . .
In the 'Root cause' section, the text should read;

However, when Application.ShowWindowsInTaskbar = FALSE, the
Document.CommandBars collection seems to ignore the CustomizationContext
and includes ALL command bars in ALL open documents.

My apologies to anyone who has wasted their time because of my inaccuracy.
 
J

Jialiang Ge [MSFT]

Hello

Thank you for your patience, I've submitted the bug to our internal office
bug report site. I'd timely inform you of any update of the issue in the
following days.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top