Is it possible to run a VBA function (Word 2007) every time the user clicks 'undo' (or crtl+z)? Thanks.
Asked
Active
Viewed 183 times
1 Answers
2
You can intercept most built-in commands in Word with VBA. See Using VBA to Control Built-In Commands in the 2007 Office System.
Try intercepting the EditUndo
command.

Jeff Rosenberg
- 3,522
- 1
- 18
- 38
-
I have that built in (to a module, which the docs suggest should work), but it's not picking it up. I've added both a `debug.print` line and a `msgbox`, and the code is not hitting either. Here is a [link to the full code](http://pastebin.com/kayUVEYL). Thanks. – David Gard Feb 13 '13 at 11:26
-
I'm not at a computer, so I can't test this for awhile, but the article I linked to uses `Sub`, not `Function`. Does changing the procedure to a `Sub` help? – Jeff Rosenberg Feb 13 '13 at 12:49
-
I've had a chance to test, and I can confirm that a `Sub` worked for me in Word 2010, while a `Function` did not. – Jeff Rosenberg Feb 13 '13 at 13:16
-
Negative on my end. Have tried with literally just the code that is in the article, and it's still not playing ball. Have tried the code in both the Normal template, and in the document that I am currently editing. Thanks. – David Gard Feb 13 '13 at 16:12
-
Hmm. I know this is a dumb question, but you are using a `.dotm` file, not `.dotx`, right? Are other macros working? – Jeff Rosenberg Feb 13 '13 at 16:15
-
Hmm, good thought. other macros are working, but it's a `.doc` (compatibility mode). I will do some testing with `.docm` a minute. – David Gard Feb 13 '13 at 16:44
-
Add no go. Just created a `docm` file and it still won't play ball. I have actually found a few other posts though were people have the same issue, and sadly the answer seems to be 'it's a but in Word 2007'! – David Gard Feb 13 '13 at 16:47
-
Yup, appears so. Works in 2003/2010, but not 2007. Sorry! – Jeff Rosenberg Feb 13 '13 at 16:49
-
I'd swear, but I'd probably be told off by a moderator! Thanks for the pointer in the first place. – David Gard Feb 13 '13 at 16:53