vba hiding a workbook

  • Thread starter Thread starter Zygoid
  • Start date Start date
Z

Zygoid

when i open an excel workbook, i have ThisWorkbook Module openin
another workbook.

Is there a vba code i can use in Thisworkbook Module to hide the 2n
workbook when it is open
 
You can hide the window, but it maybe easier to just save workbook2 in a hidden
state.

Open workbook2 and then Window|Hide
Close excel and you'll be prompted to save that workbook. If you answer Yes,
then that workbook will open hidden and you won't have anything to do in your
open routine.

But this worked for me (if the workbook only had one window):

Option Explicit
Private Sub Workbook_Open()

Dim myFileName As String
Dim wkbk As Workbook
Dim myCaption As String

myFileName = "C:\my documents\excel\book1.xls"

If Dir(myFileName) = "" Then
'no file found!
Else
myCaption = ActiveWindow.Caption
Set wkbk = Workbooks.Open(Filename:=myFileName)
If ActiveWindow.Caption = myCaption Then
'already hidden
Else
ActiveWindow.Visible = False
End If
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top