No, get rid of Sub Button1Click()/End Sub and just keep the code in the middle. It should be sandwiched betwen Private Sub Button1_Click()/End Sub.
Ok. I have done the following.. The existing code looks like this:
Sub Button1()
Existing code
Existing code
Existing code
End Sub
I have placed the code you mentioned by the lines stating existing code so it now looks like this.
Sub Button1()
Existing code
Existing code
Existing code
Private Sub Button1_Click()
With Sheets("Sheet2")
.Activate
.Shapes("Button2").Visible = True
End With
End Sub
Whenever I did it this way and clicked on button1, a message popped up stating Compile error: Expected End Sub
So, I reconfigured the code to look like this.
Sub Button1()
Existing code
Existing code
Existing code
End Sub
There is a line here separating the code
Private Sub Button1_Click()
With Sheets("Sheet2")
.Activate
.Shapes("Button2").Visible = True
End With
End Sub
Now when I run the code this way, a new popup box comes up.
It says Run-time error'2147024809 (800070057)
The item with the specified name wasn't found.
When I click on the debug, it brings up the code that I insert in Sheet2..and the arrow on the left side points to the code I have in red below.
Private Sub Worksheet_Deactivate()
Sheets("Sheet2").Shapes("Button2").Visible = False
End Sub
The name of button2 on the actual button on the screen is "button2". Additionally, within VBA in the properties area, the (Name) row is titled "button1" for button1 and "button2" for button2. Directly below that in the projects area under the modules folder, the module names are "button1" and "button2".