So I was wondering if I can reference the button that was clicked. So I do not have to change the code to much for every button. So here is what I have.
Private Sub CommandButton1_Click()
Dim name As String
With CommandButton1
If .Caption = "CommandButton1" & "" Then
name = InputBox("Enter Template Name.")
.Caption = name
End If
End With
End Sub
Instead of With CommandButton1
I want it to use the button that was clicked. I tried With Me
but it did nothing.
The answer in this SO post solves your issue.
Follow the instructions carefully. It should solve your problem. :)
EDIT:
It's pretty easy, actually.
SCREENSHOTS:
Set-up of my sheet:
Set-up of the VBE, Sheet1's code:
NOTE THE HIGHLIGHTED PARTS!
Set-up of the VBE, Class Module:
Add a class module by inserting
Class Module
rather than justModule
. The name should exactly beButtonEvents
.Result when CommandButton1 is clicked:
===============
This is just the basic premise, of course. Instead of showing a message box, you can instead change the code in the class module to have the name stored somewhere or send it to a particular cell, etc.
Hope this makes it clearer.