+ Reply to Thread
Results 1 to 15 of 15

How do I link a Ribbon check box with a macro?

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    How do I link a Ribbon check box with a macro?

    I have a macro that I execute with a button in the Ribbon.

    This macro gives the user the option to select between 2 analysis modes via an input window (Do a country specific analysis or not. If yes, what is the name of the country)

    What I would like to do is move this option to a Ribbon check box. In other words I want the user to check or not check a check box in the Ribbon depending on what type of analysis the user wants to do.

    Subsequently the user executes the macro by pressing the Ribbon button.

    I imagine that the code that links the Ribbon check box with the macro looks something like the code below. If somebody could tell me exactly how it is done that would be great.

    Please Login or Register  to view this content.
    Last edited by dschmitt; 07-05-2010 at 08:56 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do I link a Ribbon check box with a macro?

    You would need to use a callback tied to the checkbox in the XML, and have code to action that callback,like so

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I link a Ribbon check box with a macro?

    Bob, thanks for your help. But I still have some conceptual problems.

    I know how to link a sub to a button:
    Button activates Sub(control As IRibbonControl) which activates Sub()

    However with a checkBox I don't know how to do it.
    Is there a way to call the Sub(control As IRibbonControl, pressed As Boolean) with a Sub()?
    In other words can a Sub() check the status of the checkBox?
    There must be a way to do that, because with the checkBox one cannot start a Sub.

    I hope my question is comprehendable.

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

    Re: How do I link a Ribbon check box with a macro?

    If your checkboxes are just setting a flag rather than executing your macro then take Bob's example and in it store the pressed state of the checkbox.

    In you button routine check the variables and process accordingly

    For ribbon with a button and 2 checkboxes both using the same onAction callback.

    Please Login or Register  to view this content.
    Note that the checkboxes will allow for selection of both.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do I link a Ribbon check box with a macro?

    Quote Originally Posted by dschmitt View Post
    Bob, thanks for your help. But I still have some conceptual problems.

    I know how to link a sub to a button:
    Button activates Sub(control As IRibbonControl) which activates Sub()

    However with a checkBox I don't know how to do it.
    Is there a way to call the Sub(control As IRibbonControl, pressed As Boolean) with a Sub()?
    In other words can a Sub() check the status of the checkBox?
    There must be a way to do that, because with the checkBox one cannot start a Sub.

    I hope my question is comprehendable.
    A checkbox has an OnAction proiperty in the XML just as the button does, so you assign it there.

    Quite honestly, if you just have an action A or B depending upon the checkbox, I would se a togglebutton.

  6. #6
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I link a Ribbon check box with a macro?

    thanks Andy, good thinking. I actually have 2 checkBoxes on my mind.

    In regards to the sub call order I suspect that it has to be as below. Is that true?

    Please Login or Register  to view this content.
    I thought that the below may be possible but it is not working. Too bad, that would have made things easier. Can you confirm that this strategy is not possible?

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I link a Ribbon check box with a macro?

    Bob, Thanks for the hint. As you say, that would work if I would just have one toggle. I am planning for at least 2 toggles with any possible combination. I think in that case only checkboxes will work.

  8. #8
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do I link a Ribbon check box with a macro?

    As Andy said, you have to capture the state of all the checkboxes in the callback procedure, and the variables should nbe at least module in scpe so that you can use them across procedures

    Please Login or Register  to view this content.
    Last edited by Bob Phillips; 07-05-2010 at 06:36 AM.

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

    Re: How do I link a Ribbon check box with a macro?

    Sorry your logic is confusing me.

    Sub 2 appears to be the callback from a control. Either you execute code when the control is clicked or you call the routine from another controls click.

  10. #10
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I link a Ribbon check box with a macro?

    Bob, your code looks easy understandable. This is what I need. Thanks.

    Andy, you are probably confused because this logic is not possible. I tried and it didn't work. Only somebody who doesn't fully understand how IRibbonControl Subs and Subs work can come up with such a logic. A Sub cannot call a IRibbonControl Sub. Only the opposite is possible.

    I will implement this tomorrow and conclude the thread then.

  11. #11
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do I link a Ribbon check box with a macro?

    Here is an example of what I mean
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I link a Ribbon check box with a macro?

    Dear Bob and Andy, thank you very much for your help. I understand the concept now and got my checkboxes to work.
    Bob, your example xlsm file is great. The concept cannot be better illustrated.
    Last edited by dschmitt; 07-05-2010 at 09:01 PM.

  13. #13
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do I link a Ribbon check box with a macro?

    Quote Originally Posted by dschmitt View Post
    Dear Bob and Andy, thank you very much for your help. I understand the concept now and got my checkboxes to work.
    Bob, your example xlsm file is great. The concept cannot be better illustrated.
    Thanks for those words, I am glad we helped. Better still, you have a bettter understanding.

  14. #14
    Forum Contributor
    Join Date
    08-09-2012
    Location
    Anch, Alaska
    MS-Off Ver
    2003, 2010, 2013
    Posts
    131

    Re: How do I link a Ribbon check box with a macro?

    Bob , Andy,

    I have something similar to the code being discussed, is it possible to reset (un-check) the checkbox(s) after the macro has completed?

  15. #15
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How do I link a Ribbon check box with a macro?

    Hello BuckoAk, and welcome to the forum.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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