none
CommandBars.ExecuteMso to run a button in the built in toolbar of Excel 2016 RRS feed

  • Question

  • Hi,

    I´m trying to build two macros that clicks the Increase Decimals and Decrease Decimals to be able to run these with short commands instead of going Alt + H + 0 or 9 in the toolbar tabs. I've found the Ribbon names for both buttons and hopefully the right code to run them (ExecuteMso) but it does not work - running the "IncreaseDecimals" macro below adds a zero before numbers below 1000 and a thousand separator on numbers above, i.e. it adds a space instead of a .0 in the NumberFormat code. How do I get it to work exactly as the buttons in the ribbon of the Numbers Group?

    Sub IncreaseDecimal()

    Application.CommandBars.ExecuteMso "DecimalsIncrease"

    End Sub

    Sub DecreaseDecimal()

    Application.CommandBars.ExecuteMso "DecimalsDecrease"

    End Sub

    Thursday, March 8, 2018 2:54 PM

All replies

  • Your routines as written should work as expected in all Excel versions 2007 to 2016.

    Add the following to each macro, what gets returned?

    Debug.Print ActiveCell.NumberFormat

    Also try running your macros with an un-formatted cell in a new workbook containing say 123.456

    Sunday, March 11, 2018 5:20 PM
    Moderator