creating button vba then
RH

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Creating a button in VBA, then handling button clicked

Creating a button in VBA, then handling button clicked

resolvedResolved · Medium Priority · Version 2010

Atanas has attended:
Excel VBA Advanced course

Creating a button in VBA, then handling button clicked

Hi,

As I had mentioned to Jens at the time of the course, I have been trying without much success to achieve the following when a macro is run:
- the macro creates/shows on screen a couple of buttons,
- then it waits for one of them to be pressed
- depending on which button is pressed, a different sub is run
- apart from the other things the button subs would do, they would either delete the original button(s) created previously, or hide them,
- the sub also creates another button, which when pressed would create the first original buttons, or make them visible.

I have been able to create a User Form with buttons, but it just does not look good with the border, etc (and the solutions I have seen to hide the border and top bar are ridiculously complicated).

The easy ways to create a button with buttons.add do that indeed, and assign a sub to the button, but they do not make the macro stop and wait for the user to press a button in the way Excel stops when a User Form is shown.

To help understand what I a trying to do, imagine a quiz: the macro shows you a question (or a foreign word) with three buttons: know it well, know it somewhat, and don't know it. The fourth button could be End, to allow exit at any time. As you press a button, the macro will make some changes to a database, then show another word with three buttons.

Happy to provide any detail that may be helpful. Thanks in advance.
Atanas




RE: Creating a button in VBA, then handling button clicked

Hi Atanas,

Thank you for the forum question.

Please find attached workbook. I haven't coded all the buttons, but if you answer (answer 1) top button it will bring you to a new sheet with more buttons. If you press End it will bring you back to the first sheet again.

I hope it makes sense.

PS If you cannot see the attachment wait 10 minutes and refresh your browser and it will appear.





Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Attached files...

answers.xlsm

RE: Creating a button in VBA, then handling button clicked

Hello Jens,

Thank you for responding so promptly. I'm afraid I cannot see the attachment even after refreshing several times after 10mins and more. Could you share it again please? Thanks.
Best regards,

Atanas

RE: Creating a button in VBA, then handling button clicked

Ha! It had to be: as I sent my reply this line appeared at the bottom with the attachment... Please ignore it. Thanks.
Atanas

RE: Creating a button in VBA, then handling button clicked

Hi Atanas,

Good I hope you can use my idea.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Make a quick copy of a worksheet

Hold down the Ctrl key, then click and drag on a sheet tab to make a copy of that sheet. Though this process usefully copies the formats of the original sheet, note that any Range Names you have on the original sheet will be duplicated too.

To make a copy of a worksheet's contents and formats without duplicating range names: (1) Ensure that you have a blank worksheet to paste to. (2) On the sheet to copy, click on the sheet selection square to the left of Column A's heading to select the whole sheet. (2) Copy the whole sheet. (3) Paste to the blank worksheet.



View all Excel hints and tips


Server loaded in 0.05 secs.