bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I have the following class event such that if another workbook opens up then it opens up a new instance in excel. However, some of the documents we use have a notification that asks the user if they want to open as read only or not on open. The problem is when one of these documents is open my code still allows the users messages to go through to ask fi they want read only or not and then once they click then my code executes to open new instance then close old one. However, in this time it then asks the users again if they want to do read only or not. I dont want the user to even know this since instance subroutine is happening so asking twice is kind of obvious. Anyways around this such that my event executes before the message?
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)
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