Search code examples
vb.netms-wordvstooffice-addinsundo

How do you check to see if the undo button is disabled using a word vsto in vb.net?


In my vb.net vsto addon for Microsoft Word, I am trying to check to see if the undo button in the quick access toolbar is enabled or disabled. If it is disabled, it means that the undo record list is empty.

How can I check to see if the undo button is disabled?


Solution

  • Using the ID of the undo button, you can check its enabled state.

    Dim isUndoRecordEmpty As Boolean = Application.CommandBars.FindControl(Id:=128).Enabled '128 is the ID for the undo button
    If isUndoRecordEmpty = False Then 'if the undo button is disabled, meaning the undo stack is empty
        'the undo button is disabled
    End If
    

    Further information about CommandBar IDs can be found here: https://learn.microsoft.com/en-us/office/vba/api/office.commandbarcontrol.id