Make a CommandBar visible throws an exception

A

ARHangel

I have a VSTO Excel Add-In and on Application_WorkbookActivate based on some
names of the sheets I want to make a CommandBar visible or not.

I open two excels one that makes the commandbar invisible and one that does
the commandbar visible in this order. After i activate the excel with my
add-in invisible and make the other one visible when i try to make the
commandbar visible i get this error:

Error HRESULT E_FAIL has been returned from a call to a COM component.,
StackTrace: at Microsoft.Office.Core.CommandBar.set_Visible(Boolean
pvarfVisible)
at MyAddin.ThisAddIn.showHideToolbar(Boolean show) //the show parameter
is true

On my commandbar i have only this
if (toolBar.Controls.Count == 0)
{
btnMode =
(Office.CommandBarButton)toolBar.Controls.Add(
Office.MsoControlType.msoControlButton,
omissing, omissing, omissing, true);
btnMode.TooltipText = "Switch Design Mode";
btnMode.Tag = "Mode";
btnMode.Style =
Office.MsoButtonStyle.msoButtonAutomatic;
btnMode.Visible = true;
btnMode.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(btnMode_Click);
Bitmap bmp = new Bitmap(instalationPath +
"Images\\DesignMode.png", true);
btnMode.Picture = ImageConverter.ImageToIpicture(bmp);
bmp = new Bitmap(instalationPath +
"Images\\DesignMode_Mask.png", true);
btnMode.Mask = ImageConverter.ImageToIpicture(bmp);
}

The ImageConverter is a class found on the internet
public class ImageConverter : System.Windows.Forms.AxHost
{
public ImageConverter()
: base("59EE46BA-677D-4d20-BF10-8D8067CB8B33")
{
}

public static stdole.IPictureDisp
ImageToIpicture(System.Drawing.Image image)
{
return
(stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image);
}

public static System.Drawing.Image IPictureToImage(stdole.StdPicture
picture)
{
return ImageConverter.GetPictureFromIPicture(picture);
}
}

Can you tell help me find the reason why i have this exception?

Thanks in advance
 

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