1
votes

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
1
You need to specify the workbooks and worksheets. When you open another one, it becomes ThisWorkbook. Or, do If ThisWorkbook.Name = "firstWorkBook" Then Thisworkbook.hide or something.BruceWayne
If ThisWorkbook.Name = "hide_sheet" Then ThisWorkbook.Hide End IfBamboo LikeFox
Still not working Sir..I'd been searching this online but with no good.Bamboo LikeFox

1 Answers

1
votes

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