Link button name to a cell
Hi Needa,
The best I have been able to come up with is to use the worksheet activate
event for the sheet which has the buttons because you only want the buttons
to be updated when you change back to that sheet. Each time you select the
worksheet with the buttons, the captions get updated.
You could either update the captions directly from the sheet names or from
the cells with the names in them.
Something you need to know is that each worksheet has a code name which is
not changed when you rename the worksheet. You can see them in the project
explorer part of the VBA editor. The names are Sheet1, Sheet2 etc and the
name that you can change is the one in brackets. However, you can still refer
to the worksheets by the code name as I have done in the code below because
that name never changes. Note that the code names are not the same as
Sheets(1), Sheets(2) etc which refer to the sheets from left to right in the
workbook.
In the code I have demonstrated changing the caption by copying the cell
reference and also directly copying the worksheet given name.
Private Sub Worksheet_Activate()
With Sheet1
.Cells(6, 3) = Sheet2.Name
.CommandButton2.Caption = .Cells(6, 3)
.Cells(10, 3) = Sheet3.Name
.CommandButton3.Caption = Sheet3.Name
.Cells(14, 3) = Sheet4.Name
.CommandButton4.Caption = Sheet4.Name
.Cells(18, 3) = Sheet5.Name
.CommandButton5.Caption = Sheet5.Name
End With
End Sub
Hope it helps.
Regards,
OssieMac
|