I have 2 Excel workbooks one contains Macros and the other workbook calls Macro workbook.
In main workbook open event Macro workbook will be opened in the same application instance and when the workbook closes I am closing Macro workbook and after that I have written Appication.Quit, but here the problem is after closing Macro workbook one blank excel remians open.
How to close the blank workbook through VBA?
By the way I am facing this issue in Office 2007 and 2010 only in 2013 there is no blank excel.
Below is the code in Macro.xlsm
- Module1
Public Sub Test()
MsgBox "Test"
End Sub
Public Sub Auto_Close()
ThisWorkbook.Saved = True
End Sub
Below is the code in Test.xlsm - Thisworkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Workbooks("Macro.xlsm").Close
Module1.CodeFileClose
End Sub
Private Sub Workbook_Open()
Module1.CodeFileOpen
End Sub
Below is the code in Test.xlsm - Module1
Public Sub CodeFileOpen()
Application.Workbooks.Open ("C:\Macro.xlsm")
Application.Run "Macro.xlsm!Test"
End Sub
Public Sub CodeFileClose()
MsgBox "Before Close"
Application.Quit
End Sub