Forum Discussion
VBA Form Command Button not working
I'm going out of my mind trying to resolve this issue. I have succeeded at creating and using macros without issue, yet all my efforts at testing a simple VBA form command button based on youtube instructions fall flat. I have spent several days researching every possible cause and solution without success. I have even gone as far as removing and reinstalling Microsoft 365, as well as factory resetting Excel by deleting Excel's folder using RegEdit. My non-form macros work without issue. Yet creating a single form command button to general a VBA MsgBox fails to work. Please keep in mind that I usually have no difficulties resolving any problems that come my way. This time however, NOTHING!. NADA!
3 Replies
- Sleppy52Copper ContributorUPDATE: I did everything I could think of to reset my 2nd-hand computer. Not much to risk since I bought expressly to work with Excel anyways. I just couldn't understand why macros I had previously recorded to do certain things in my spreadsheet worked without fail. And yet in following that fairly detailed Youtube tutorial for creating an input form failed to bring up a message box, leaving me to belief VBA wasn't working for me.
So I decided to try following a different YouTube tutorial (How to Create a Data Entry Form in Excel) to see what might happen in coding the first command button. Not that it called up a message box, but at least it responded as expected. So at this point, I'll just leave it there, and hope there wasn't really a problem with my Exel. - SnowMan55Bronze Contributor
"creating a single form command button to general [generate?] a VBA MsgBox fails to work."
That's a bit vague. Are you attempting to create a form (UserForm) that the user will interact with, which will contain this command button? Or are you attempting to place a (form) command button on a worksheet? (Or possibly both.)
In the former case, your MsgBox statement will go into the Click event handler for the button you create. That event handler will be part of the code module for the form. (What user action do you intend to occur to cause the form to be displayed? The click of a button on a worksheet? A particular change to a particular cell value? Some other user action?)
In the latter case, your MsgBox statement will go into a macro for the button you create. That macro is part of a standard code module (which Microsoft ambiguously calls just a module, but there can exist: standard code modules not associated with any particular worksheet, worksheet code modules, workbook code modules, userform modules, class modules…). (Excel would have prompted you for the name of the macro as soon as you created the button.)Here's how the Project Explorer window (a child of the VB Editor window) might appear. (Solver is an add-in that you might not be using; it is not required for this problem.)
Edit: Oh, and are you using Excel for Windows, or Excel for Mac?
- Sleppy52Copper ContributorSnowMan55, I am using Excel 365 for Windows. Admittedly, I might have screwed things up after creating my first macro, which caused the first "Security Risk" message to appear just below the ribbon. Not knowing at the time how to properly respond, I may have inadvertently blocked VBA from being used. After that, I was attempting to create an input/edit UserForm for my Wordbook based on examples found on YouTube. (i.e. "How to create an excel VBA data entry form with update and search funtion.")
I have abandoned all efforts of creating an input form and just focussed on trying to get a form based on one single command button to cause a message box to appear on screen when the button is clicked.
As I detailed before, I have tried pretty much every standard solution found by googling the issue. None of them have worked except using RegEdit to delete Excel's key folder HKEY_CURRET_USER. That at least restored one of the two Security Risk messages appearing when first attempting to use VBA in a workbook.
I'm sorry to say, SnowMan55, your comments and directions fail to address the point of my inquiry. I'm thinking now, I probably need to "factory reset" MS Office's key folder from under HKEY_CURRET_USER.