+ Reply to Thread
Results 1 to 9 of 9

xl2007 ribbon editbox update

Hybrid View

thevoid xl2007 ribbon editbox update 05-23-2011, 09:08 AM
Andy Pope Re: xl2007 ribbon editbox... 05-24-2011, 04:01 AM
thevoid Re: xl2007 ribbon editbox... 05-24-2011, 04:52 AM
thevoid Re: xl2007 ribbon editbox... 05-24-2011, 05:03 AM
thevoid Re: xl2007 ribbon editbox... 05-24-2011, 08:00 AM
thevoid Re: xl2007 ribbon editbox... 05-24-2011, 08:25 AM
Andy Pope Re: xl2007 ribbon editbox... 05-24-2011, 08:29 AM
royUK Re: xl2007 ribbon editbox... 05-24-2011, 08:06 AM
thevoid Re: xl2007 ribbon editbox... 05-24-2011, 08:59 AM
  1. #1
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    xl2007 ribbon editbox update

    hi

    I'm trying to customize the ribbon, in order to include my macros
    already joined in an addin-workbook.

    My problem is the following: how can I copy/imitate the behaviour of the
    editbox displaying the fontformat found in the built-in Home tab. I mean the
    feature that the value in it updates when changing between worksheets.

    I'm familiar with the events and customUI basics, I just haven't found a solution.

    Thank you in anticipation
    istvan

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: xl2007 ribbon editbox update

    You will need to use the Callbacks to update the ribbon controls. Also you will need to monitor workbook level events to detect worksheet change.

    Are you trying to mimic the font control or was that just an example?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: xl2007 ribbon editbox update

    My macro's purpose is to have a control in the ribbon to ease freezing panes, 2 editboxes, one for the column, one for the row, and by changing between sheets, these editboxes should represent the freezed row/column.

    I thought that would be the way to make things work as you wrote.

    But I couldn't find the right event.

    My idea was catch the change of worksheet with event's callback, then trigger the InvalidateControl method of the ribbon.
    And this way the getText method of the runs and so the editbox is updated.

    The event I've found for catching the change of a sheet was 'sheet_activate()' but as far as I know it should be defined in the eventually activated sheet's code.

    My question is which event should be used, an event that the callbakc procedure could be situated somewhere in the addin-workbook's code.

    thanks in advance
    istvan

  4. #4
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: xl2007 ribbon editbox update

    Hi

    I just got the event: workbook_sheetactivate
    It works for sheets in other open workbooks as well, if this is added to an addin's thisworkbook's code.

    istvan

  5. #5
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: xl2007 ribbon editbox update

    Hi

    I've just made it

    in the addin's module:
    Public myRibbon As IRibbonUI

    Sub Ribbon_customization_OnLoad(ByVal ribbon As Office.IRibbonUI)
    Set myRibbon = ribbon
    End Sub

    Sub set_freezerow(control As IRibbonControl, Text As String)
    If IsNumeric(Text) Then
    with activewindow
    .splitrow = CInt(Text)
    .FreezePanes = True
    end with
    End If
    End Sub

    sub get_freezerow(control As IRibbonControl, ByRef Text)
    If Not ActiveWindow Is Nothing Then
    Text = ActiveWindow.SplitRow
    Else
    Text = -1
    End If
    End Sub

    in the addin's workbook object:

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    myRibbon.InvalidateControl "ebox_set_row"
    End Sub

    in the customUI.xml:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_customization_onLoad">
    <tabs>
    ...

    <editBox id="ebox_set_row"
    label="Freeze rows"
    maxLength="2"
    onChange="set_freezerow"
    getText="get_freezerow"
    sizeString="2"/>
    ...
    </tabs>


    I have one final problem. That is the myribbon variable could be easily cleared (by an 'end' statement, error in a macro, stc.), is there a workaround so that the ribbon (and the controls) could be accessed without this intermediate variable?

    yours
    istvan

  6. #6
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: xl2007 ribbon editbox update

    Hi

    I've just made it

    in the addin's module:
    Public myRibbon As IRibbonUI
    
    Sub Ribbon_customization_OnLoad(ByVal ribbon As Office.IRibbonUI)
         Set myRibbon = ribbon
    End Sub
    
    Sub set_freezerow(control As IRibbonControl, Text As String)
         If IsNumeric(Text) Then
         with activewindow
              .splitrow = CInt(Text)
              .FreezePanes = True
         end with
         End If
    End Sub
    
    sub get_freezerow(control As IRibbonControl, ByRef Text)
         If Not ActiveWindow Is Nothing Then
            Text = ActiveWindow.SplitRow
         Else
              Text = -1
         End If
    End Sub
    in the addin's workbook object:
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
         myRibbon.InvalidateControl "ebox_set_row"
    End Sub
    in the customUI.xml:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_customization_onLoad">
    <tabs>
    ...
    
    <editBox id="ebox_set_row"
         label="Freeze rows"
         maxLength="2"
         onChange="set_freezerow"
         getText="get_freezerow"
         sizeString="2"/>
    ...
    </tabs>
    I have one final problem. That is the myribbon variable could be easily cleared (by an 'end' statement, error in a macro, stc.), is there a workaround so that the ribbon (and the controls) could be accessed without this intermediate variable?

    yours
    istvan

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: xl2007 ribbon editbox update

    Avoid the use of END statement.

    Here is an article on handling the potential lose of the ribbon object
    http://blogs.office.com/b/microsoft-...on-object.aspx

    You can also store values to a temporary sheet. But if lose of variable scope is a regular problem I would investigate the cause rather than code around it.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: xl2007 ribbon editbox update

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Registered User
    Join Date
    05-20-2011
    Location
    Budapest
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: xl2007 ribbon editbox update

    Hi

    thanks for the solution, nice workaround.

    It will do.

    istvan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1