How to inspect clipboard text for particular formatting prior to pasting into Word... RRS feed

  • Question

  • I've found Word's newer Paste options to be rather irritating--my coworkers often have to paste text that's been formatted as underlined and strickenthrough from one document to another while preserving the formatting.  Unfortunately, if you paste as "Merge Formatting," the underlining stays and the strikethroughs disappear.  This is a big deal for us--we've set everyone's default settings to "Keep Source Formatting," but it is still possible to override this with an errant mouseclick if you are a right-click-menu paster (which many of our users are).

    I was thinking that I could write a VBA routine that triggered off of any paste event (Sub EditPaste()) and:

    a) Checked to see if the paste was a Merge Format paste, and

    b) Checked whether the text in the clipboard had any strikethrough formatting.

    If both conditions are true, the user would be presented with a dialog box noting that the strikethrough formatting would be lost, and given the option of cancelling the paste.

    Alternatively, it could:

    a) Check whether the text in the clipboard had any strikethrough formatting.

    b) Check whether the text in the selected text range that results from the paste operation has strikethrough formatting.

    If (a) is true and (b) is false, then display the dialog and use an "undo" if the user didn't mean to paste it that way.

    Unfortunately, I am at a complete loss as to how to do this.  All of the web pages I've found on using the clipboard from VBA involve the DataObject object, and it seems to only store string info (not formatting).  Any ideas?



    • Moved by Bill_Stewart Tuesday, October 30, 2012 8:55 PM Move to more appropriate forum (From:The Official Scripting Guys Forum!)
    Tuesday, October 30, 2012 8:51 PM