We have made an excel add in that is installed correctly and will only show up when opening Excel from the main icon (or a blank workbook). It will NOT show up on the toolbar when opening any existing saved excel document.
I have made sure that when opening an existing document, under file -> options -> add in, it is correctly checked in the COM add ins. For us to use our add in, we have to open up a blank workbook, and drag our existing file to the blank workbook.
Would anyone have any idea why it would only show up in the ribbon on a blank workbook and not on existing .xlsx files?
I have even ran a test where I open a blank workbook, confirm the add in is on the ribbon, put some text in a cell, save it to my desktop, close it, and then reopen it. It then does NOT show up. This add in was made with VS2010.
Here is the code from "ThisAddIn.cs"
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
Here is the code from the Ribbon.cs file that we made...all it is doing is populating a few fields and setting up:
private void MyRibbon_Load(object sender, RibbonUIEventArgs e)
{
Excel._Workbook activeWorkbook = (Excel._Workbook)Globals.ThisAddIn.Application.ActiveWorkbook;
if (activeWorkbook.Path == "")
{
string pathMyDocuments = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
this.editBox1.Text = pathMyDocuments;
}
else
{
this.editBox1.Text = activeWorkbook.Path;
this.fileBox.Text = "Converted_" + activeWorkbook.Name;
}
this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer;
this.folderBrowserDialog1.ShowNewFolderButton = true;
//populate the dropdown box with spreadsheet templates
using (SqlConnection conn = new SqlConnection("<removed for stack overflow>"))
{
using (SqlCommand command = new SqlCommand("<sql command text removed for SO", conn))
{
command.CommandType = CommandType.Text;
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
item.Label = reader["MasterSpreadsheetName"].ToString();
ddlSpreadsheetTemplate.Items.Add(item);
}
}
}
}
Sorry for the late answer, but it is very common problem, so I will answer anyway. I encountered it myself a few times, and it had nothing to do with the code of my addin. The problem was in preview pane in explorer. When you select your excel file in Explorer, it starts an instance of Excel for preview. And then you open your file in real Excel, some bug in Excel prevents all the addins to load. Your addin won't even start any code, so you cannot do anything from inside of your addin. The only way is not to use preview with excel files. And even worse, after one file is previewed, the Excel process still hangs in memory, so addins won't work until you kill it from taskmanager. This bug is in Excel 2007, 2010, 2013 and maybe even 2016.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With