(Office 365 ProPlus version 1701 build 7766.2099, running on Windows 7)

(Edited post, original is lower.)ActiveX command buttons that occur in a template in a different order than they were created can call the wrong macro, when a file is created from that template.

Exact steps to reproduce:Create a new document. Save it as a .dotm file. Press enter a couple times to create space at the top of the document. Create an ActiveX Command Button. Double-click it to create procedure, put in MsgBox to ID it. Create a second button ABOVE the first, and its procedure. Now, when the buttons are clicked in the template, they work fine (top one reports 2, bottom reports 1), but when clicked in a file created from the template (double-click file in Explorer window), they are swapped (top reports 1, bottom reports 2).

(Original)A very long time ago (earlier version of Word), I created a Word template (.dotm) with buttons that run macros. It used to work fine. I've recently discovered that the buttons now call the wrong macros. If I double-click the template file (creating a new file based on the template), the first button calls the third button's macro and vice-versa. (Middle button, "Fill out forms", works fine.) If I right-click the template and choose Open (open the template itself, not create a new file), the buttons work as designed.

I've boiled the template down to just the 3 buttons and their macros (see photos), and am still seeing the same issue. Clicking "Reset fields", which should call ResetFieldsButton_Click(), instead runs MyPrintButton_Click(). (I get the "Printing..." popup.) What's going on?buttonsenter image description here

  • The same document of course - I'm obviously tired. I'd try recreating the buttons in the template (copy of the template) with new names, see if that works. If not, try recreating the template. If that still doesn't work I'd try MacroButton fields instead of ActiveX controls.– Cindy MeisterFeb 13 at 20:08
  • I verified the exact same behavior in a new template created for the purpose - create 3 ActiveX buttons, create their macros, then cut the third one and paste it into the document before the first one. On a related note, I tried removing the original 3 buttons and replacing them with 3 new ones, carefully keeping them in the correct order, and setting up new subs for them to call. As before, everything works fine when clicking them in the template - but now a new document doesn't react at all when they're clicked.– whairstFeb 13 at 20:23
  • Ugh. Sounds like a problem in the new version. I'll test it tomorrow and see if I can replicate it– Cindy MeisterFeb 13 at 20:25
  • My test: New file; insert some text; insert three ActiveX command buttons; double-click each button in turn and add a MsgBox line of code; turn off Design Mode; click each button. Worked fine. Save As *.dotm and close. Create a new doc from the template, test the buttons. They work correctly. Is it possible you copy/pasted the CommandButton controls instead of insert new ones each time? Version 1708 by the way, updated semi-annually.– Cindy MeisterFeb 14 at 8:35
  • Cindy, to get mine to fail, I selected and "cut" the third button, then pasted it above the first one in the document - so they were no longer in the order that they were created. I suspect the sequence they're in the document is what makes the difference - despite having the correct names.– whairstFeb 14 at 12:19

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.