none
Detect Format Painter or other built-in toggle is pressed? RRS feed

  • Question

  • Is there a way to detect that the user has activated Format Painter toggle in Word (or any built-in toggle for that matter)? If Format Painter is active, certain code in WindowSelectionChange event may cancel the Format Painter. I would like to exit the WindowSelectionChange event if the user is clicking to paste a format when Format Painter active. Thanks!

    Monday, December 16, 2013 6:45 PM

Answers

  • I don't think there's anyway to detect the double-click, at least, not without using the Windows API...

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by wordyone Tuesday, December 17, 2013 8:47 PM
    Tuesday, December 17, 2013 7:28 PM
    Moderator

All replies

  • I'm actually not sure if this really helps you or not but this routine executes when the Format Painter button is clicked.

    Sub CopyFormat()
        Selection.CopyFormat
    End Sub
    
    If you included the routine and added a set of a boolean variable then theoretically it would seem that you could check the value and take some other action in the WindowSelectionChange event.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, December 17, 2013 2:20 AM
  • Hi wordyone

    The only way to detect whether any particular built-in toggle command has been triggered is to use custom Ribbon XML (as part of an add-in, for example) with a Commands section containing a <command> element for each idMso you want to track. Use the onAction attribute to "re-purpose" the command for whatever reason you want to know when the button has been triggered.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 17, 2013 2:18 PM
    Moderator
  • Thank you both for the suggestions. The tricky thing about the Format Painter button is that I need to know when it has been double-clicked...I am not sure how I would distinguish it has been activated via single click vs double-click when repurposing this one. (After the user double-clicks to persist the paste format mode is when the mode is subsequently being cancelled by the WindowSelectionChange event processing.)

    I tried Rich's idea of CopyFormat but the sub gets hit on the first click of the FormatPainter button. Even if I could set a boolean to track when FormatPainter has been clicked, I don't know how I would detect that the FormatPainter mode has been ended by the user. Perhaps there's some easier way to approach this that I'm overlooking.

    Tuesday, December 17, 2013 4:56 PM
  • I don't think there's anyway to detect the double-click, at least, not without using the Windows API...

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by wordyone Tuesday, December 17, 2013 8:47 PM
    Tuesday, December 17, 2013 7:28 PM
    Moderator
  • Thanks. As an FYI, the Format Painter is getting cancelled when the GoTo method is used on a Range object. As in:

    Range.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")

    Tuesday, December 17, 2013 11:35 PM