Here are the two websites and code that I could find, the websites, the code used and the results of each.
1.I tried the code from this website first:
--------------------------------
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
'This checks to make sure the user is opening one of my forms and not another Excel document
If Sheet1.lblMainMenu.Caption <> "Main" Then
MsgBox "If you need to open another Excel Workbook, please click on Start/Programs/Microsoft Office/Microsoft Excel" & vbCrLf & _
"After Excel opens then click on File/Open and then try to open your file.", vbInformation, "PHIS Request Forms"
'This closes out of the form they tried to open and reactivates my form
ActiveWorkbook.Close
Windows("Access Request Form (New User).xls").Activate
End If
End Sub
---------------------------------
When I placed this code into ThisWorkbook, I get the following error message:
"Compile Error:
Method or Data Member not found"
It errors at ".lblMainMenu" and other workbooks were still able to open in the same instance of excel.
2. The second code I tried came from the following website:
with the following code:
------------------------------------
Put this in a class module called cApp:
Public WithEvents CApp As Application
Private Sub CApp_WorkbookOpen(ByVal wb As Excel.Workbook)
' Capture opened workbook info
Dim sPathName As String
sPathName = wb.Path & "\" & wb.Name
' Close it and open it in a new instance
wb.Close
Dim NewExcel As Excel.Application
Set NewExcel = CreateObject("Excel.Application")
With NewExcel
.Visible = True
.Workbooks.Open (sPathName)
End With
End Sub
Put this in a module:
Option Explicit
Public ClassApp As New CApp
Public Sub YourSub()
' Initialize and instantiate your class object to access application events.
Set ClassApp.CApp = Excel.Application
End Sub
-----------------------------------
While this did not create an error, it did not work as other workbooks were still able to open in the same instance of excel instead of opening in a new instance.
Hopefully I have included enough information and hopefully, there is a way to achieve this. Let me know if you need any further details.