+ Reply to Thread
Results 1 to 4 of 4

Open new excel instance - bug

Hybrid View

  1. #1
    Registered User
    Join Date
    02-11-2008
    Posts
    68

    Open new excel instance - bug

    Hello,

    I have a workbook and I want to make it open in a new excel instance.

    All subsequent workbooks should also be opened on new excel instances..

    I am using this code in the workbook_open event

    Dim xlApp As Excel.Application
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    xlApp.Workbooks.Open Filename:=ActiveWorkbook.FullName
    DO NOT TEST THIS CODE.

    It opens the same workbook 100+ times until the computer hungs up.

    could someone help ? tapapad
    Last edited by tapapad; 04-06-2008 at 07:26 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    The code opens a new copy of Excel
    It then opens a copy of the same file that has your Workbook Open macro.

    When the book is opened the new copy of Excel runs trhe WorkbookOpen macro causing the macro to open another new copy of excel.

    This process continues until you run out of memory


    Their is nothing wrong with you code for opening a new copy of Excel
    It is either the file iot is opening or the fact it is placed in the WorkbookOpen macro
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    02-11-2008
    Posts
    68
    mudraker,

    thanks for the feedback.

    My ultimate goal is to open this "workbook" in a separate EXCEL instance and prevent other workbooks being opened in the same EXCEL instance as this "workbook".

    I have researched this subject quite a lot but didn't come to a viable solution.

    If you can assist, I would be very grateful to you.

    tapapad

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello tapapad,

    This macro will open a workbook in an new instance of Excel from the workbook the macro is in. Each time you call the macro, the named workbook will be opened in another instance of Excel. Place this macro in a standard VBA module.
    'Written: April 06, 2008
    'Author:  Leith Ross
    'Summary: Opens an Excel workbook in a new instance of Excel.
    
    
     Private Declare Function ShellExecute _
      Lib "Shell32.dll" _
        Alias "ShellExecuteA" _
         (ByVal hWnd As Long, _
          ByVal lpOperation As String, _
          ByVal lpFile As String, _
          ByVal lpParameters As String, _
          ByVal lpDirectory As String, _
          ByVal nShowCmd As Long) As Long
    
    Sub StartNewExcelInstance(WkbFullName As String)
    
      Dim CmdLine As String
        
       'Command line string - file names must include quotes
        CmdLine = "/e " & Chr$(34) & WkbFullName & Chr$(34)
        
         'Open the Workbook in another instance of Excel
          RetVal = ShellExecute(0&, "", "EXCEL.exe", CmdLine, vbNullString, 1&)
    
    End Sub
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    Calling the Macro
    StartNewExcelInstance "C:\My Documents\Test.xls"

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1