Reputation: 35
I have a userform with 2 command buttons : hide and show.
This work if I only have 1 workbook open. I can simply hide and show the workbook from the form. However If I have another workbook open let say Book1. and then I click Hide, It will also hide the Book1. I want only to hide the specific workbook.
Here's my code:
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Application.Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Application.Visible = True
End Sub
Upvotes: 1
Views: 833
Reputation: 12497
Should be something like this
Option Explicit
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Workbooks("Book1.xlsx").Windows(1).Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Workbooks("Book1.xlsx").Windows(1).Visible = True
End Sub
Another Example that work on both Excel 2010 & 2013
Option Explicit
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Windows(ThisWorkbook.Name).Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Windows(ThisWorkbook.Name).Visible = True
End Sub
Upvotes: 1