bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I am using the following code to basically catch any workbooks opened while my main workbook is opened. And it converts it to read only then closes it and starts it under its own instance of excel. It helps to keep my workbook seperate from all other ones. The problem is if the workbook being opened has the read only message option enabled then it asks "The author would like you to open "tracker.xls" as read only unless you need to make changes. Open as read-only?". I want to stop it from asking that until the workbook as been opened in its own instance. The issue is the App_WorkbookOpen(ByVal Wb As Workbook) event happens after the other workbooks message event happens. My code is set up as a class as shown below:
Thisworkbook
Code:
'Creating seperate instances using events
Public WithEvents App As Application
'Create a seperate instances for any excel files trying to open while this is open
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
MsgBox "test"
Dim xlApp As Application
If Wb Is ThisWorkbook Then
Exit Sub
End If
If Wb.ReadOnly <> True Then
Application.DisplayAlerts = False
Wb.ChangeFileAccess xlReadOnly
Application.DisplayAlerts = True
End If
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open Wb.FullName
xlApp.Visible = True
Wb.Close False
'Just for this program since it seems to leave window back open again
ThisWorkbook.Application.Visible = False
End Sub
Thisworkbook
Code:
Public Sub Workbook_Open()
On Error GoTo ErrorHandler
'Speed up vba code
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Icon Update
Call SetIcon(ThisWorkbook.Path & "\Images\LOGO.ico", 0)
'Seperate instance classes and GUIClass
Public ExcelGUIUpdates As New ExcelGUIClass
'Seperate Instance Declaration
Set ExcelGUIUpdates.App = Application
'Delete itself from history
Call ExcelGUIUpdates.DeleteRecentlyOpened
Exit Sub
ErrorHandler:
Debug.Print "Error Number: " & Err.Number & ", Error Message: " & Err.Description & ", Last DLL Error: " & Err.LastDllError
End Sub
Last edited: