mobigital

I am getting this occasional COM error when trying to ensure that Document Task pane is visible:

This code:
Globals.ThisWorkbook.Application.CommandBars["Task Pane"].Visible = true;

Causes this exception:
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.

at Microsoft.Office.Core.CommandBar.set_Visible(Boolean pvarfVisible)



Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

Douglas H. Troy

Perhaps, before you attempt to access the properties for that control, you should validate that the object exists ...





Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

mobigital

Task Pane definitely exists.

I can open it by hand through the View menu or CTRL-F1





Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

Douglas H. Troy

Well, I'm more familiar with Word VSTO solutions than Excel, but I'm betting this is going to be some kind of "timing" issue, where either the Task Pane object is not available (invalid) or inaccessible (for whatever reason). I just hacked out a VSTO Word project, and in the Startup event handler, I added the following code:

// will hold an instance of Task Pane Commandbar
private Office.CommandBar _TaskPaneCommandBar;
....

// get Task Pane object
_TaskPaneCommandBar = Globals.ThisDocument.CommandBars["Task Pane"] as Office.CommandBar;
// validate it (debug only)
Debug.Assert(_TaskPaneCommandBar != null, "The task pane object is invalid at this point!");
// use it
_TaskPaneCommandBar.Visible = true;

Try it out, see what happens ... just for giggles.





Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

mobigital

It seems to start failing when I open another work book in Excel and go back to my VSTO workbook.

Should having additional open workbooks interfere with opening Task Pane

Is there a reliable way to open or close task pane from my VSTO assembly





Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

mobigital

on that note, how do I tell Actions Pane to show specifically "Document Actions" tab

Sometimes it shows "Getting Started", and toggling Actions Pane visible between true and false does not change anything.





Re: Visual Studio Tools for Office COM Exception in CommandBars["Task Pane"].Visible = true

John R. Durant - MSFT

For example, you can set Application.DisplayDocumentActionTaskPane to True in the Workbook_Activate event.

Best