Sorry, I missed the reference to Office 365 in the subject line. That's what I'm using too (to be precise, build 11330.20014).
ActiveX controls were badly broken in Excel 2007, which was more an issue with Office 2007 rather than ActiveX, but by SP2 they weren't quite so bad. But in general, as I noted, ActiveX controls can be rather flaky, despite nominally looking nicer and being more full-featured than Form controls. This was true in Excel 2003 and earlier, and it's been true in Excel 2010 and later. But when my clients use them, then so do I.
And so I duplicated your situation. I made a workbook with Sheet1 and Sheet2, then I hid Sheet2, and created CommandButton1 on Sheet1. I right clicked on the button, and inserted your two lines of code into the procedure stub that Excel inserted in the Sheet1 code module.
Then, the moment of truth. I turned off Design Mode, then clicked the button. Sheet2 became visible and then was activated.
I can think of a couple things that may have gone wrong. Make sure the button name matches the procedure name. And don't type the entire procedure yourself, but use a right click to view the code, which inserts the appropriately named procedure in the appropriate code module, usually the module behind the sheet that contains the button.
Jon Peltier said:I can think of a couple things that may have gone wrong. Make sure the button name matches the procedure name. And don't type the entire procedure yourself, but use a right click to view the code, which inserts the appropriately named procedure in the appropriate code module, usually the module behind the sheet that contains the button.Click to expand...
* the code has been auto gen'ed, I've just entered the two statements
* the function matches the name of the button given that it was auto-gen'ed.
Again, I can sometimes open this 'sample' document and have the ActiveX control work. I don't need to change anything, maybe just restart the computer.
I was handed this task by a less experienced developer who had the same problem on his computer, and our computers come from different images and manufacturers - the only consistency is that we are both using Office365 rather than a retail release, and we're both using Windows 10.
I've attached an image to illustrate this a bit better. In the linked document there is 1 button. You can see 2 buttons, but thats what happens most of the time when these ActiveX buttons are clicked.
Unfortunately, there appears to be a bug in the mrexcel.com forum that prevents the image link embedding from working. Here is the raw URL: