On one workbook (A), I have a button that opens another workbook (Main.xls) and then proceeds to close the first workbook. The problem is that once it finishes closing Workbook A, if another workbook is open, it then maximizes whichever workbook it happens to feel like, and not necessarily the one I want it to, even though I have specifically activated it. Perhaps I could put a variable specifying the book I want in the BeforeClose Sub of Workbook A. (I do not always the same book to be active after closing Book A so it would have to be done with a variable.) Any suggestions would be greatly appreciated. Many thanks!
This is the code that opens the workbook that I want to be active
This is the ThisWorkbook Code that is used to prevent changes to the workbook (A) that is being closed.
Code:
Public Sub Back_To_Main()
Application.ScreenUpdating = False
Application.EnableEvents = False
Call Open_Main 'OpenWorkbooks module
Workbooks("Main.xls").Activate
Application.ScreenUpdating = True
Application.EnableEvents = True
ThisWorkbook.Close False
End Sub
Code:
Public Sub Open_Main()
On Error GoTo ErrorHandler
Workbooks("Main.xls").Activate
ActiveSheet.Unprotect Password:=PW
Range("A14").Value = 0
Range("G17").Select
ActiveSheet.Protect Password:=PW
Exit Sub
ErrorHandler:
Workbooks.Open Filename:=ThisWorkbook.Path & "\Main.xls"
ActiveSheet.Unprotect Password:=PW
Range("A14").Value = 0
Range("G17").Select
ActiveSheet.Protect Password:=PW
End Sub
This is the ThisWorkbook Code that is used to prevent changes to the workbook (A) that is being closed.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.MoveAfterReturnDirection = xlDown
ActiveWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.Saved = True
Cancel = True
End Sub