6

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);
      }
    }
  }
}
blapsley
  • 132
  • 1
  • 8
  • including the code for the addin starup might be useful – Sorceri Dec 18 '12 at 16:27
  • ThisAddIn.cs file has nothing in the "ThisAddIn_Startup" or "ThisAddIn_Shutdown", but I posted it in the edit above. – blapsley Dec 18 '12 at 17:20
  • Open an existing doc, go to File > Options > Add-Ins. See if your add-in is listed as active or inactive. – Keith Dec 18 '12 at 21:18
  • Also try setting the environment variable [VSTO_SUPPRESSDISPLAYALERTS](http://msdn.microsoft.com/en-us/library/ms269003(v=vs.80).aspx) and see if you get any error messages when you open an existing doc. – Keith Dec 18 '12 at 21:19
  • It is an active add in on the options addins menu. I set that environment variable above with a value of '0'. No message boxes popped up on file open. – blapsley Dec 18 '12 at 21:58
  • Do you have 2 different versions of Excel on your machine? – Franchesca Jan 21 '13 at 16:48
  • No. I have a fresh install of 2010. – blapsley Jan 21 '13 at 20:03
  • Make sure it's not a case of the ribbon is being loaded but the tab text is not being shown - try clicking just to the left of the last tab in the toolbar, this appears to be a bug when you try and update text in the ribbon on the 'Load' event. – lo_toad Apr 12 '13 at 10:21

1 Answers1

1

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. enter image description hereWhen 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.

Alex Butenko
  • 3,664
  • 3
  • 35
  • 54
  • 1
    Man what a frustrating, weird error. I was getting this too with a user and one of our add-ins. Add in worked fine if you opened excel on its own, but did not work if you opened an already-saved file. The user must have used Outlook to do a preview and then excel was left running in the background. Going to task manager and ending all Excel instances helped! And I guess the rule is **Don't Use Outlook Previews** – Max Mar 21 '18 at 11:00
  • @Max yes, I guess it is about any Excel preview, not only Explorer's. – Alex Butenko Mar 21 '18 at 13:39