I have created an excel worksheet, lets call it 'pricing'. On pricing there is a command button 'notes' which when pressed will a) hide 'pricing' and b) make visible and select a second worksheet called '-notes-'. The user can then make notes and then to return the pricing sheet by pressing a command button 'back' on the -notes- sheet. The back button needs to a) hide the -notes- sheet and b) make visible and select pricing sheet.
Some of the workbooks that 'pricing' will be copied into will not have a -notes- sheet so the 'notes' button on the pricing sheet will also need to A)check that there is a sheet called -notes- and if there isn't one, it will need to create it and B) it will need to create the 'back' button and the code so when the back button is pressed, will hide -notes- and then make visble and select 'pricing'. It is this B that I am having trouble with. I can create the button and name it 'Back', but I don't know how to get it to hide -notes- and make visible and select 'pricing'.
Here is the code that checks for the -Notess- sheet and creates it if there isn't one:
Public Sub notesButton_Click()
Dim s As Worksheet
Dim sName As String
sName = ActiveSheet.Name
Dim result As Boolean
result = False
For Each s In ThisWorkbook.Sheets
If s.Name = "-notes-" Then
result = True
End If
Next
If result = False Then
Sheets.Add.Name = "-notes-"
Worksheets(sName).Visible = xlSheetVeryHidden
Worksheets("-notes-").Buttons.Add(500, 1, 81, 39).Select
Selection.Name = "Back"
Selection.OnAction = "Back"
ActiveSheet.Shapes("Back").Select
Selection.Characters.Text = "Back"
Worksheets("-notes-").Shapes("Back").OnAction = "!<wsclose>"
Else
Worksheets("-notes-").Visible = True
Worksheets("-notes-").Select
Worksheets(sName).Visible = xlSheetVeryHidden
End If
The line:
Worksheets("-notes-").Shapes("Back").OnAction = "!<wsclose>"
is the issue. I am trying to get the button to run this sub when clicked:
Public Sub wsclose()
Worksheets(sName).Visible = True
Worksheets(sName).Select
Worksheets("-notes-").Visible = xlSheetVeryHidden
End Sub
however, when I click the back button i get the following message:
'Cannot run the macro "Renewal Oricing Sheet v3.xls'!wsclose'. The macro may not be available in this workbook or all macros may be disabled'