Automatically add border to picture? RRS feed

  • Question

  • I'd like to write (or at least find) a macro that automatically adds a black, 1.5 pt border to any picture imported into the document.  Most tutorials for macros and VBA tell you how to assign a keyboard shortcut to your macros, and searches for "automatic macros" only yield info about macros that run when opening/closing a document.  I just want to create a document where this behavior is triggered every time a picture is added.

    Also, if you could briefly explain the principle that allows me to attach macros to regular tasks like this, instead of running them with a keyboard shortcut, I would be grateful.

    Friday, October 11, 2013 4:02 PM


  • Hi A1

    The reason you can't find information on this is because it's not something Word VBA supports in the way you envision.

    Something that triggers on a specific action is called an "event". No event is fired when inserting a picture - Word has very few events.

    For some commands, it's possible to use Ribbon XML embedded in a document to intercept specific Ribbon commands. (In this case, the command name would be PictureInsertFromFile.) The command element in the Ribbon XML would assign the onAction attribute to a macro in your document that performs the steps required.

    Unfortunately, this macro is not something we can just hand you code for, as the steps depend very much on some of the settings in your Word environment and the version of Word you use.

    All in all, it would probably be simpler for you to run a macro that adds the border to all the pictures in the document? Then all we'd need from you is to know which "wrapping" option you're using...

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 11, 2013 4:14 PM