Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default VBA to return how many Excel instances are open

Could someone help me with code that will tell me how many instances of
Excel are currently open?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default VBA to return how many Excel instances are open

Hi Tod,

Could someone help me with code that will tell me how many instances of
Excel are currently open?


Sure (careful with the word-wrap):

Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal
hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Function ExcelInstances() As Long

Dim hWndDesk As Long
Dim hWndXL As Long

'Get a handle to the desktop
hWndDesk = GetDesktopWindow

Do
'Get the next Excel window
hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, "XLMAIN", vbNullString)

'If we got one, increment the count
If hWndXL 0 Then
ExcelInstances = ExcelInstances + 1
End If

'Loop until we've found them all
Loop Until hWndXL = 0


End Function


Regards

Stephen Bullen
Microsoft MVP - Excel

Professional Excel Development
The most advanced Excel VBA book available
www.oaltd.co.uk/ProExcelDev


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to open 2 Instances of Excel 2007 jvaughn75 Setting up and Configuration of Excel 5 April 26th 10 07:32 PM
Open Multible Instances of Excel AJOLSON Excel Discussion (Misc queries) 3 September 15th 09 03:12 PM
Open 2 instances of Excel Dan Excel Discussion (Misc queries) 2 July 3rd 07 07:26 AM
Open separate instances of excel Waterboy Setting up and Configuration of Excel 5 April 25th 07 02:58 PM
to open multiple instances of excel slickS Excel Discussion (Misc queries) 0 August 21st 06 11:23 PM


All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"