0

I am developing a VSTO Add-in for Excel and I want to add a new CustomTaskPane (userAdminTaskPane) to each new opened Excel document by this code and make it visible:

public static void CreateUploadFile(string name)
        {
            string fileName = String.Concat(name, ".txt");
            string filePath = Path.Combine(Properties.Settings.Default.workingDir,fileName);
            File.WriteAllText(filePath, Properties.Resources.UploadTemplate,Encoding.Unicode);
            Globals.ThisAddIn.Application.Workbooks.OpenText(filePath,Excel.XlPlatform.xlMSDOS,1,Excel.XlTextParsingType.xlDelimited,Excel.XlTextQualifier.xlTextQualifierDoubleQuote,false,true);
            mainTaskPane userAdminTaskPane = new mainTaskPane();
        }

How can I do this? should I handle specific events or can I do this for new Excel Documents created using this method only?

proless8
  • 57
  • 1
  • 9
  • If you haven't already, take a look at the Add-in Express library. It makes adding ribbons etc much easier, as well as helps out a lot in dealing with differences in all the office versions. – Marc Bernier Dec 12 '19 at 21:53
  • Perhaps set it up like I have here in repro steps: https://stackoverflow.com/q/10526118/495455 – Jeremy Thompson Dec 12 '19 at 22:29
  • Are you using a ribbon in your project? If so, you can use the [`Ribbon_Load`](https://github.com/Excel-projects/Script-Help/blob/master/CS/Scripts/Ribbon.cs#L148-L187) event. Here is one of my [Excel Addins](https://github.com/Excel-projects/Script-Help) for reference – aduguid Dec 12 '19 at 23:46
  • @aduguid yes i am, a button in the ribbon calls this method. – proless8 Dec 13 '19 at 05:45
  • @MarcBernier well i can't use 3rd party library for this, since this would overkill for this specific project. Thanks. – proless8 Dec 13 '19 at 05:57
  • 1
    I'd work with the appropriate events, such as `WorkbookOpen`, `NewWorkbook` `Workbook.BeforeClose`. As I recall, that's also the approach Microsoft uses in its documentation for handling task panes in the pseudo-SDI environment. Here's the documentation article, but Excel is not represented as the article was written before it was forced into pseudo-SDI: https://learn.microsoft.com/en-us/visualstudio/vsto/custom-task-panes?view=vs-2019 – Cindy Meister Dec 13 '19 at 11:55

0 Answers0