Bamboo LikeFox
Bamboo LikeFox

Reputation: 35

Hide a specific workbook via userform in vba

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

Answers (1)

0m3r
0m3r

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

Related Questions