Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Getting all open files in Excel

I am trying to get a list of all files that Excel currently has open. I say
files in that it can be a mixture of .xla and .xls files (talking Excel 2003
here).

I can just loop through the workbooks collection to get .xls files.

I can then loop through the Addins to get the .xla files...except it doesn't
get them all. Below is the function I am using (ExistsInCollection just
detects if a key (2nd param) links to an index in a collection (1st param)).
What is interesting is I have some .xla files I add via the installer, and
others I open programatically when a .xls opens, thus they aren't in the
Addin list, nor do they show up in the Workbooks collection. I am trying to
do this WITHOUT going through the VBE collection since that opens a security
hole.

Function OpenAddins() As Collection

Dim inx As Integer
Dim colAddins As New Collection

For inx = 1 To Application.AddIns.Count

If ExistsInCollection(Workbooks, Application.AddIns(inx).Name) Then

colAddins.Add Application.AddIns(inx).Name

End If

Next inx

Set OpenAddins = colAddins

End Function

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003

  #2   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Getting all open files in Excel

The .xla you open, not install, won't be in the workbooks collection. I
usually test if the addin is open through this:

Property Get CodeXLAisOpen(AddinName As String) As Boolean
'//////Checks if Addin is open

Dim FileNum As Integer
Dim ErrNum As Integer
Dim V As Variant
Dim Filename As String

On Error Resume Next


Filename = Range("PathCode") & AddinName

''''''''''''''''''''''''''''''''''''''''''''
' if the file doesn't exist, it isn't open
' so get out now
''''''''''''''''''''''''''''''''''''''''''''
V = Dir(Filename, vbNormal)
If IsError(V) = True Then
' syntactically bad file name
CodeXLAisOpen = False
Exit Property
ElseIf V = vbNullString Then
' file doesn't exist.
CodeXLAisOpen = False
Exit Property
End If

FileNum = FreeFile()
'''''''''''''''''''''''''''''''''''''''
' Attempt to open the file and lock it.
'''''''''''''''''''''''''''''''''''''''
Err.Clear
Open Filename For Input Lock Read As #FileNum
ErrNum = Err.Number
''''''''''''''''''''
' Close the file.
''''''''''''''''''''
Close FileNum
On Error GoTo 0

''''''''''''''''''''''''''''''''''''''
' Check to see which error occurred.
''''''''''''''''''''''''''''''''''''''
Select Case ErrNum
Case 0
''''''''''''''''''''''''''''''''''''''''''''
' No error occurred.
' File is NOT already open by another user.
''''''''''''''''''''''''''''''''''''''''''''
CodeXLAisOpen = False
Case 70
''''''''''''''''''''''''''''''''''''''''''''
' Error number for "Permission Denied."
' File is already opened by another user.
''''''''''''''''''''''''''''''''''''''''''''
CodeXLAisOpen = True
Case Else
''''''''''''''''''''''''''''''''''''''''''''
' Another error occurred. Assume closed.
''''''''''''''''''''''''''''''''''''''''''''
CodeXLAisOpen = False
End Select
End Property

Of course, you will need a list of the addins you would pass to Filename to
test for....

Dan

"J Streger" wrote:

I am trying to get a list of all files that Excel currently has open. I say
files in that it can be a mixture of .xla and .xls files (talking Excel 2003
here).

I can just loop through the workbooks collection to get .xls files.

I can then loop through the Addins to get the .xla files...except it doesn't
get them all. Below is the function I am using (ExistsInCollection just
detects if a key (2nd param) links to an index in a collection (1st param)).
What is interesting is I have some .xla files I add via the installer, and
others I open programatically when a .xls opens, thus they aren't in the
Addin list, nor do they show up in the Workbooks collection. I am trying to
do this WITHOUT going through the VBE collection since that opens a security
hole.

Function OpenAddins() As Collection

Dim inx As Integer
Dim colAddins As New Collection

For inx = 1 To Application.AddIns.Count

If ExistsInCollection(Workbooks, Application.AddIns(inx).Name) Then

colAddins.Add Application.AddIns(inx).Name

End If

Next inx

Set OpenAddins = colAddins

End Function

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003

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
emailing files from excel, the files will not go until I open up . joe New Users to Excel 2 September 18th 09 02:12 PM
how do I toggle between 2 open excel files and leave both open Big D in Brighton Excel Discussion (Misc queries) 1 November 6th 08 04:28 PM
How to change default Open/Files of Type to "Microsoft Excel Files Tammy Excel Discussion (Misc queries) 2 January 14th 08 11:06 PM
I cant open files unless I open the Excel program first ElaineAng Excel Discussion (Misc queries) 3 February 16th 06 02:54 PM
Can not open excel files without open application Taarfa Excel Discussion (Misc queries) 3 July 9th 05 11:56 PM


All times are GMT +1. The time now is 09:48 PM.

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

About Us

"It's about Microsoft Excel"