none
Excel Add-in - Detect when a user is in header/footer edit mode? RRS feed

  • Question

  • I'm looking for a way to detect when the user has placed their cursor inside the header/footer area. 

    I want to display a group of buttons on my add-in and have the group disappear when the user is not editing the header/footer. 

    I was trying to achieve this using the selection change event and checking if the Header/Footer Contextual tab was visible using the snippet below but the selection change event doesn't fire when the user places the cursor inside the header/footer areas of the worksheet. 
                

    Excel.Application xlApp = Globals.ThisAddIn.Application; 

    bool enabled = xlApp.CommandBars.GetVisibleMso("TabHeaderAndFooterToolsDesign");


    Am I just out of luck? Is there no active way to check for this? 


    • Edited by jasonlbeal Monday, January 20, 2014 3:00 PM Updating based on some attempts I've tried.
    Monday, January 20, 2014 4:38 AM

Answers

  • Hello jasonbeal,

    The Word Object Model doesn't provide any event for notifying whether the view is active or not.

    There is no need to detect whether a particular ribbon tab is visible. Instead, you can add your own tab to the list of contextual ones:

    The following markup was used for getting the job done:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="LoadedCallback" loadImage="ImagesCallback">
      <ribbon startFromScratch="false">
        <contextualTabs>
          <tabSet idMso="TabSetHeaderAndFooterTools">
            <tab getLabel="LabelCallback" getVisible="VisbleCallback" id="myContextualLabel">
              <group getLabel="LabelCallback" getVisible="VisibleCallback" id="myContextualGroup">
                <button getEnabled="EnabledCallback" getLabel="LabelCallback" getVisible="VisibleCallback" id="myContextualButton" onAction="ActionCallback" />
              </group>
            </tab>
          </tabSet>
        </contextualTabs>
      </ribbon>
    </customUI>   
    You can read more about this in the series of articles in MSDN -Customizing the 2007 Office Fluent Ribbon for Developers .

    • Marked as answer by jasonlbeal Monday, January 20, 2014 6:17 PM
    Monday, January 20, 2014 5:03 PM

All replies

  • Hello jasonbeal,

    The Word Object Model doesn't provide any event for notifying whether the view is active or not.

    There is no need to detect whether a particular ribbon tab is visible. Instead, you can add your own tab to the list of contextual ones:

    The following markup was used for getting the job done:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="LoadedCallback" loadImage="ImagesCallback">
      <ribbon startFromScratch="false">
        <contextualTabs>
          <tabSet idMso="TabSetHeaderAndFooterTools">
            <tab getLabel="LabelCallback" getVisible="VisbleCallback" id="myContextualLabel">
              <group getLabel="LabelCallback" getVisible="VisibleCallback" id="myContextualGroup">
                <button getEnabled="EnabledCallback" getLabel="LabelCallback" getVisible="VisibleCallback" id="myContextualButton" onAction="ActionCallback" />
              </group>
            </tab>
          </tabSet>
        </contextualTabs>
      </ribbon>
    </customUI>   
    You can read more about this in the series of articles in MSDN -Customizing the 2007 Office Fluent Ribbon for Developers .

    • Marked as answer by jasonlbeal Monday, January 20, 2014 6:17 PM
    Monday, January 20, 2014 5:03 PM
  • Hi Eugene

    This works well for toggling my buttons on / off but now I run into a similar problem. Since I can't detect if the user is in the Left Header, Center Header or Right Header, how can I inject static text into the location where the user has positioned their cursor when they click the button on the Tab? 


    • Edited by jasonlbeal Monday, January 20, 2014 8:01 PM clarification
    Monday, January 20, 2014 8:00 PM
  • Hi Jason,

    First of all, I'd recommend asking separate questions in newly created threads, not use threads marked as answered.

    Note, Word allows recording the macro code automatically. If you try to turn on the macro recorder and then try to edit headers or footers you will see the following code:

    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

    Friday, January 24, 2014 4:30 PM