Skip to first unread message

Chad Kelley

Sep 17, 2021, 9:21:59 PM9/17/21
to Excel-DNA
So i have a couple questions here and i will jump right in.
I have an Excel DNA Addin with quit a few things going on.

1. Can I have Multiple Ribbons with Callbacks?

  public class USExcelRibbon : ExcelRibbon
//Callbacks for USEcelRibbon Here

In a completely different class:
 public class USExcelRibbonTwo : ExcelRibbon
//Callbacks for USEcelRibbon Here

My goal is to have a ribbbon for each business unit within our orginization.  I have a class that determins who the user is and shows the appropriot ribbon.
I may have up to 6 ribbons in which different bussiness unit may need features and others may not.  I determine if the Ribbon group is shown by the follwoing:

*.dna File
  <group id="DataGroup" label="Data Files" getVisible="GetVisible">
          <splitButton id="splitButton" size="normal" >
            <button id="button" imageMso="TableExcelSpreadsheetInsert" label="Replay CSV " />
            <menu id="menu">
              <button id="CaliberDataFileReplayBtn"
                         screentip="Replays a Caliber or Meyers files"
                         supertip="Replays a caliber log (*.csv) Or Meyers Adt (*.adt) File.  Caliber files must have the header section at the top of file and must contain the file extention (*.csv).  Meyers files must contain the file extention (*.adt)"
                         label="Caliber/Meyers" />
              <button id="DataFileReplaySlidingSleevebtn"
                      screentip="Replays Files while being written too"
                      supertip="Replays a meyers (*.adt) and strips out the zone from the file.  
                            Example is the file has 49 Zones worth of data but you only want to replay Zone 10.  Thsi action can be completed while the (*.adt) file is being written to by mview."
                      label="Sliding Sleeve Replay" />
              <!--<button id="DataFileReplayFracProBtn"
                      screentip="Fracpro Data File Replay"
                      supertip="Will replay a Fracpro File"
                      label="FracPro" />-->
              <button id="DataFileReplayIgnitionBtn"
                      screentip="Ignition Data File"
                      supertip="Will replay an Ignition Data File"
                      label="Ignition" />

getVisible Function:
 public bool GetAccess(IRibbonControl control)
            if (control.Id == "AccountsRecievableId")
                return UserExistsFracFocus();

            if (control.Id == "AdminGroupId")
                return UserExistsAdmin();

            if (control.Id == "ForecastingGroupID")
                return UserExistsForecast();

            if (control.Id == "AzureGroupId")
                return true;

            //Return True for Groupd not Above
            return true;

Trying this i get two seperate ribbons showing up based on users seems to be a challenge.

When a user clicks a button on the ribbon i Get the Open Excel Docuemnt and Determine if that Document is the correct one based on the Keyword of the Document added:

 public Workbook GetOpenWorkbook(string KeyWord)
            List<OpenWorkBookModel> Books = new List<OpenWorkBookModel>();
            foreach (Workbook Book in ExcelApplicationBooks)
                OpenWorkBookModel view = new OpenWorkBookModel
                    ExcelBook = Book,
                    Filename = Book.FullName,
                    KeyWord = Book.Keywords
                view.Version = view.GetVersion();

            var BookByKeyWord = Books.Where(o => o.KeyWord == KeyWord).Select(o => o.ExcelBook).ToList();
            if (BookByKeyWord.Count > 1)
                return ExcelApplication.ActiveWorkbook;
            else if (BookByKeyWord.Count == 1)
                return BookByKeyWord.First();
            return null;

My problem is that when i get the OPEN workbooks when a user clicks a Button the Application Object may not contain the open Workbooks within the Application Object.  I get the Application Object using the Follwing:


however it seems when a user Select File >> Open and Opens a Naother document the Appliction Object Only Contains a Single workbook and Not TWO as i expect.
I have looked at Windows API and getting the EXCEL.ExE Process but i feel that's complicated.  Any thoughts on dealing the the SDI and Excel 2013 64 bit?

FYI: our company is moving to Office 365 soon.

thanks for any information you can provide,

thanks for the work on excel-dna.  I love it.

Govert van Drimmelen

Sep 21, 2021, 8:45:30 AM9/21/21
to Excel-DNA
Hi Chad,

Yes, you can have multiple ribbon classes in your add-in.
I would suggest that you move the xml ribbon markup into the code, rather than put this in the .dna file.
So you'll have:

    public class USExcelRibbon : ExcelRibbon
        public override string GetCustomUI(string RibbonID)
            return @"
          <tab id='tab1' label='MyRibbon Test'>
            <group id='group1' label='My Group'>
              <button id='button1' label='Test' onAction='OnButtonPressed'/>
            </group >

        //Callbacks for USEcelRibbon Here

And similar for the other ribbon class.

Another option, which might be even better, is to have a single ribbon that defines multiple  <tab > tags, and then have a "getVisible" callback that lets you decide whether a tab should be visible or not.

The Workbooks collection should work right and have all the workbooks that are open in the process. I suspect you have some problems in the code related to "ExcelApplicationBooks" or "OpenWorkbookModel".
If you think there is a problem with the Workboooks collection, I suggest you start a new discussion thread with a small self-contained bit of code that I can test. 


Chad Kelley

Sep 21, 2021, 11:29:13 AM9/21/21
to Excel-DNA
Hye Govert,
I will give the " GetCustomUI" a go this morning. 

For the Workbooks Collection:

I can Open excel 2013 >> File Open >. Select Excel File.

If I Open another excel File by Simply Double clicking on it i can't capture that workbook.  I think it has something to do with Excel creating Multiple Instances.  therefore the Application Object can only see workbooks within it's Instance.

private Microsoft.Office.Interop.Excel.Application App { get; set; } = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;

If i open a Workbook, then inside this workbook go to File >> Open and Select Another workbook then my App Object conatins all the Workbooks (two in this Case).  but if the user actually minimizes the first workbook and navigates to anothe file Double clicks it then my App Pbject doesn't pick up both workbooks.  I think this will have to be a Windows API Call unless DNA has a trick?

Reply all
Reply to author
0 new messages