I have an unexpected display when closing a new workbook !
I launch my macro from the command line.
Application is made invisible from workbook_open :
Sub workbook_open()
Application.Visible = False
UserForm1.Show
Application.Visible = True
End Sub
UserForm1 contains a single button.
-> Only the userform is displayed.
Pressing the button starts the following code :
Sub UnexpectedDisplay()
Dim NewBook As Workbook
Debug.Print "_______________"
Application.Visible = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set NewBook = Workbooks.Add
With NewBook
.Title = "MyTitle"
.Subject = "Display"
.SaveAs Filename:="MyWorkbook"
End With
Debug.Print ActiveWorkbook.Name
MsgBox "New workbook added"
NewBook.Close SaveChanges:=True
Debug.Print ActiveWorkbook.Name
MsgBox "Workbook closed"
Application.DisplayAlerts = True
End Sub
The first msgbox is displayed : "New workbook added"
-> Only the msgbox is displayed.
Press "Ok"
The second msgbox is displayed : "Workbook closed"
Debug Trace :
_______________
MyWorkbook.xlsx
MyMacroFile.xlsm
-> A workbook becomes visible
( when MyMacroFile.xlsm is opened?).
-> Question : How to avoid this.
workbook_openis application.visible=true. It looks like it's right, as the activeworkbook will be the one calling the code, you are closing newworkbook, so put the same before opening and see what it is then? Does the other workbook itself open another further workbook. - Nathan_Sav