How many Instances of Excel are open

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
In Workbook1 in its “ThisWorkbook” module I have a “Workbook_Open” event that automatically opens Workbook2 (reference file) when Workbook1 is opened.

Question; are Wb1 and Wb2 open in the same instance of Excel or in 2 separate instances
 
All it that is meant to occure is: Open Book1 and it auto opens Book2, close Book1 via Red X and BOTH workbooks are Saved and Closed.

This is placed in ThisWorkbook module of Book1.xlsm
VBA Code:
Sub Workbook_Open()
  Dim pWB As Workbook
       Application.ScreenUpdating = False
     Workbooks.Open ("C:\Users\Me\Documents\My Documents\Book2.xlsm")
   Set pWB = ThisWorkbook
    With pWB.Windows(1)
       pWB.Activate
    End With
     Application.ScreenUpdating = True
  End Sub
This is in ThisWorkbook module of Book1.xlsm
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   Dim wb As Workbook
       Application.ScreenUpdating = False
     'Loop through each workbook
   For Each wb In Application.Workbooks
     'Close the workbooks and save changes.
   If wb.Name <> ThisWorkbook.Name Then
      wb.Close SaveChanges:=True
     DoEvents
    End If
  Next wb
    ThisWorkbook.Save
     Application.Quit
     Application.ScreenUpdating = True
End Sub
If it’s of any any help, have added a snip image of Task Manger after “Save/Close” sub has run.

TaskManager Snip.JPG
 
Last edited:
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You didn't say what you expect it to do and what it is doing.
When I run it that code closes both workbooks and any others that are open at the time and quits excel.
I thought that is what you wanted to do
 
Upvote 0
You must have read #11 before I finished making an edit.
All it that is meant to occure is: Open Book1 and it auto opens Book2, close Book1 via Red X and BOTH workbooks are Saved and Closed

Yes it is exactly what I want to, but I can’t get to the bottom of why I still have the Ghost/Blank instance of Excel open
as you can see in the snip image
 
Upvote 0
Close excel and check you task manager.
If there is still an Excel instance running kill it in task manager.
Open your book 1 by double clicking the workbook in explorer which should open book 2
Check your task manager again. How many instances of Excel do you have open ? It should only be 1.
 
Upvote 0
Think snip image below will show you better than I can describe.
"001 Fert-Chem-Nozzle........." is the one I've previously referred to as Book1 (is the primary)
and "aaFert_&_Chem……." is Book2


TaskManagerSnip2.JPG
 
Upvote 0
See if this closes all tasks:
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   Dim wb As Workbook
       Application.ScreenUpdating = False
     'Loop through each workbook
   For Each wb In Application.Workbooks
     'Close the workbooks and save changes.
   If wb.Name <> ThisWorkbook.Name Then
      wb.Close SaveChanges:=True
    End If
  Next wb
    ThisWorkbook.Save
    ThisWorkbook.Close
    Application.ScreenUpdating = True
 Application.Quit
End Sub
 
Upvote 0
Appreciate your suggestion.
Afraid to say it didn’t close ALL instances of Excel.

I currently have 3 Subs in standard modules (all slightly different) that when attached to a command button, ALL of them save & close ALL instances of Excel that are open. But NONE of them do it when re-titled “Before Close” and placed in Book1 (primary book "ThisWorkbook".)
It’s not in my nature to leave something unresolved (dog with a bone syndrome) but on this occasion I am seriously thinking that sorting this is ALL a waist of everybody’s time!!!???
 
Upvote 0
If you follow the same steps as in Post #15 but in task manager click on processes, do you EXCEL.EXE twice ?
I assume you are on windows 7 right ?
 
Upvote 0
Yes Windows 7.
Only one occurrence of EXCEL.EXE*32
 
Upvote 0
That has me beat. If after you open the workbook which then opens the other workbook you only have one EXCEL.EXE running, then application.quit should have closed the only instance that is running.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top