Is there any way to prevent multiple instances of excel? So that if I click an excel shortcut instead of opening a new instance of the exe it just brings my already open excel application to the front?
Thanks
Printable View
Is there any way to prevent multiple instances of excel? So that if I click an excel shortcut instead of opening a new instance of the exe it just brings my already open excel application to the front?
Thanks
I found this code and it has help me with a similar problem. You will need to adjust the code to fit your needs.
[VBA]Option Explicit
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
Set xlApp = Application
If xlApp.Workbooks.Count > 1 Then
MsgBox "This workbook cannot be opened if other " _
& "workbooks are already opened"
Me.Close savechanges:=False
End If
End Sub
Private Sub Workbook_Close()
Set xlApp = Nothing
End Sub
Private Sub xlApp_NewWorkbook(ByVal Wb As Workbook)
If xlApp.Workbooks.Count > 1 Then
Wb.Close savechanges:=False
MsgBox "Can't create a new workbook now!"
End If
End Sub
Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)
If xlApp.Workbooks.Count > 1 Then
Wb.Close savechanges:=False
MsgBox "Can't open a new workbook now!"
End If
End Sub[/VBA]
Thanks for the info. Although this looks more like it would prevent multiple workbooks in the same application instance not prevent multiple instances of an application.