Consulting

Results 1 to 3 of 3

Thread: prevent multiple instances of excel

  1. #1
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location

    prevent multiple instances of excel

    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
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  2. #2
    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]

  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •