Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VSTO project Command bar question

176 views
Skip to first unread message

Chuck Hartman

unread,
May 13, 2005, 1:09:31 PM5/13/05
to
During my VSTO Beta2 project's Startup event handler, I create a TaskPane
control and then add, position and make visible a new CommandBar to the
Application's CommandBars collection. Everything works as expected when the
project is started by opening a Word document from the local file system,
however, when the project is started by opening a URL from a web server and
Word is hosted in an IE window, my VSTO project does not seem to have any
control whatsoever over Word's Command Bars.

I have tried enumerating all visible CommandBar objects contained in
Application.CommandBars after I add my new CommandBar during my Startup
event handler. It appears to be in the collection and is marked visible.
In addition, there are two Word CommandBars (Reviewing and Formatting) that
are visible that I want to hide, but I am unable to hide them. I do not
catch any exceptions during this process, but my new CommandBar is not
present when IE finishes opening the document. I observe the same results
whether I use AttachedTemplate or ActiveDocument for the
CustomizationContext. I have also tried adding the CommandBar to the
project's template. The CommandBar then does show up in the list of
available CommandBars, but I am still unable to make it visible when the
document opens.

All other aspects of my VSTO project seem to work as expected when Word
opens a URL and the project starts from an IE window, except for the
CommandBars. Any suggestions? Thanks.

Chuck Hartman

Ken Laws [MSFT]

unread,
May 13, 2005, 6:02:01 PM5/13/05
to
Hi Chuck,

I see the same behavior when adding custom command bar via a VSTO project
and then loading the document via a URL so that the document is opened within
Internet Explorer.

Basically when Internet Explorer is hosting Microsoft Word the application
toolbars are hidden and the Word toolbars that you are seeing are in essence
a copy of the application toolbars that have been added to the Word document
so that they are visible.

I thought that we may be able to add the custom toolbar to the document
object instead, however, in this scenario customization of the tool bars is
disabled.

Unfortunately, I haven't been able to find a workaround that would make the
toolbar visible in this scenario.

Let me do some additional research and get back to you.

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support

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

For more information regarding Visual Studio Tools for Office 2005:

Best of Blogs: Visual Studio 2005 Tools for Office
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landvsto2005_ta.asp

Visual Studio Tools for Office Forum
http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16

Visual Studio Tools for the Microsoft Office System
http://msdn.microsoft.com/office/understanding/vsto/default.aspx

Ken Laws [MSFT]

unread,
May 16, 2005, 2:21:03 PM5/16/05
to
Hi Chuck,

The only way that I've been able to have the custom command bar displayed
when loading the document from a URL is to create the command bar and save it
to the document rather than creating the command bars when the VSTO project
is loaded.

Having the command bar stored with the document allowed me to be able to
display the command bar when the document was opened from the URL.

From my VSTO project I then used the FindControl method to locate the
controls and sink the event for the control.

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support

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

For more information regarding Visual Studio Tools for Office 2005:

Visual Studio Tools for the Microsoft Office System
http://msdn.microsoft.com/office/understanding/vsto/default.aspx

Chuck Hartman

unread,
May 17, 2005, 5:11:18 PM5/17/05
to
Hi Ken,

I have tried a few more things and have duplicated the behavior that you
observe. I was hoping that the command bar only needed to exist in the
document before opening from a URL. But even if I put an empty custom
command bar in the document template that is used to create a new document,
I still cannot add the command bar buttons during the loading of the VSTO
project. Actually, they ARE added without error, but they do not show up.
As you have said, it appears that customizations are disabled at that point.
Exactly what is preventing command bar customizations at this point (IE,
Word, VSTO runtime, ...)? Is this a bug that may eventually be fixed or
working as designed?

Unfortunately, this seems to be a major setback for my project. It is very
important that the buttons contained in my custom command bar be able to
evolve over time as my customers gain skills with my solution and request
new features. They will want the latest command bar buttons even when
editing the first document that was created on the server after thousands
more documents have been created on the server.

If the problem is being caused by the IE hosting environment, I could
possibly look into using the shell to invoke local copy of Word from the IE
hyperlink. I would rather not have to go down this path due to the security
issues and the resulting additional complexity for my almost clueless end
users (not to mention having manage multiple windows). Thanks for your
continued help.

Chuck Hartman

"Ken Laws [MSFT]" <KenLa...@discussions.microsoft.com> wrote in message
news:EE9CA500-60FA-499A...@microsoft.com...

Ken Laws [MSFT]

unread,
May 18, 2005, 12:41:20 PM5/18/05
to
Hi Chuck,

The behavior with the command bars is not specific to VSTO as I have been
able to reproduce the same behavior when adding the command bars from a COM
Add-in.

The behavior is a result of Microsoft Word being hosted within Internet
Explorer. I suspect that the behavior may be by design, however, I would
strongly urge you to submit a bug for this issue by navigating to the link
listed below and then clicking on the "Report a Bug" link on the page.

http://lab.msdn.microsoft.com/productfeedback/

Short of using some method that would cause Microsoft Word to load the
document without being hosted within Internet Explorer, such as the shell
option that you mentioned, the only other possible option that I've found was
to add a ToolStrip control to the ActionsPane to basically simulate your
custom command bar within the Actions Pane window which is displayed when
opening the document from a URL.

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support

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

For more information regarding Visual Studio Tools for Office 2005:

Visual Studio Tools for the Microsoft Office System
http://msdn.microsoft.com/office/understanding/vsto/default.aspx

--
Regards,

Ken Laws
Microsoft Support


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

Chuck Hartman

unread,
May 18, 2005, 5:01:13 PM5/18/05
to
Ken,

Bug report FDBK27326 has been submitted.

So far, I have not been able to come up with any fixes or workarounds that
meet my requirements for usability and security. If anyone else thinks this
is a usabiity or security issue when trying to open a Word document when
hosted by IE, please vote on this bug report at:

http://lab.msdn.microsoft.com/productfeedback/

Thanks.

Chuck Hartman

"Ken Laws [MSFT]" <KenLa...@discussions.microsoft.com> wrote in message

news:A1E322CA-B14E-4E31...@microsoft.com...

Chuck Hartman

unread,
May 20, 2005, 5:38:31 PM5/20/05
to
Ken,

I'm really sorry if this seems to be a topic that will not die. I am now
seeing additional evidence of what you imply below and this new observation
seems to be a related issue.

After my VSTO project opens the Word document from a URL, almost immediately
I call the ThisDocument.SaveAs() method to give the document a new name and
to make sure that the document is not in a read-only state. Also, my
CommandBar changes are not made to the document until after the document is
saved at least once. Therefore, the original document read from the URL
should not have had any changes made to it.

The client is then free to edit the document. When done, they use a button
on my Actions Pane that calls the ThisDocument.SaveAs() method twice to save
the document into the client's Temp directory in two different formats. It
then sends both copies of the document back to the server via an HTTP POST
request from a WebClient object. That all works fine.

The issue occurs when the client navigates IE away from the open Word
document, either forward to a new URL or backward via the browsers Back
button. If (and only if) changes have been made to the original document
opened by IE, they get asked whether or not they want to save changes. On
the surface this is not totally unexpected, however, as suggested in several
MSDN articles, I am setting the ThisDocument.Saved property to true during
my BeforeClose event handler (and also MANY other places in my code) to
avoid that dialog box. My project knows whether the document is dirty would
like to have full control of all document saving.

It appears that the BeforeClose event is NOT being raised for my copy of the
ThisDocument object prior to the dialog box being presented. Separately, I
have also noted that if I press the Save button on Word's Standard
CommandBar, the BeforeSave event is not raised. This makes be believe that
my VSTO project's ThisDocument object is a copy of the document opened by IE
and not the actual document. It also appears that some of the document's
properties and events are being handled elsewhere and they are not being
reflected to my VSTO project.

If I could understand better what is happening here, I might have hope of
developing a workaround. If you would like me to resume this discussion in
another thread or in another newsgroup, please let me know where you think
it should go. Thanks again for your past assistance.

Chuck Hartman

"Ken Laws [MSFT]" <KenLa...@discussions.microsoft.com> wrote in message

news:2B569920-73B8-487E...@microsoft.com...
> Hi Chuck,
>
> ...


> Basically when Internet Explorer is hosting Microsoft Word the application
> toolbars are hidden and the Word toolbars that you are seeing are in
> essence
> a copy of the application toolbars that have been added to the Word
> document
> so that they are visible.

> ...

0 new messages