PC Review


Reply
Thread Tools Rate Thread

Code to list concurrently open workbooks

 
 
DaveO
Guest
Posts: n/a
 
      19th Jun 2008
From the Excel menu you can click >Windows and see a list of
concurrently open files. Is there VBA code to capture that list
programmatically?

For instance: to touch all the cells in a selection, the code is
For Each rCell in Selection.Cells
...snip
next rCell

Is there similar For Each code that will scroll through a list of open
workbooks?

Thanks,
Dave O
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      19th Jun 2008
Try something like this:

Sub test()

Dim oWB As Workbook
Dim oAddin As AddIn

For Each oWB In Application.Workbooks
MsgBox oWB.Name
Next oWB

For Each oAddin In Application.AddIns
If oAddin.Installed Then
MsgBox oAddin.Name
End If
Next oAddin

End Sub


RBS


"DaveO" <(E-Mail Removed)> wrote in message
news:9d0a7fe9-b9f9-4a54-9356-(E-Mail Removed)...
> From the Excel menu you can click >Windows and see a list of
> concurrently open files. Is there VBA code to capture that list
> programmatically?
>
> For instance: to touch all the cells in a selection, the code is
> For Each rCell in Selection.Cells
> ...snip
> next rCell
>
> Is there similar For Each code that will scroll through a list of open
> workbooks?
>
> Thanks,
> Dave O


 
Reply With Quote
 
DaveO
Guest
Posts: n/a
 
      19th Jun 2008
That's what I was looking for, thanks!
 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      19th Jun 2008
The posted code will miss out on add-ins that are open, but not loaded as an
add-in.
This code will correct that:

Sub test2()

Dim i As Long
Dim oProject
Dim oWB As Workbook
Dim collWorkbooks As Collection

Set collWorkbooks = New Collection

On Error Resume Next

For Each oProject In Application.VBE.VBProjects
collWorkbooks.Add FileFromPath(oProject.Filename, False), _
FileFromPath(oProject.Filename, False)
Next oProject

For Each oWB In Application.Workbooks
collWorkbooks.Add FileFromPath(oWB.Name, False), _
FileFromPath(oWB.Name, False)
Next oWB

For i = 1 To collWorkbooks.Count
MsgBox collWorkbooks(i)
Next i

End Sub


RBS


"DaveO" <(E-Mail Removed)> wrote in message
news:68adf48f-dc4b-4fc5-b78b-(E-Mail Removed)...
> That's what I was looking for, thanks!


 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      19th Jun 2008
Forgot to post the FileFromPath function:

Function FileFromPath(ByVal strFullPath As String, _
Optional bExtensionOff As Boolean) As String

Dim FPL As Long 'len of full path
Dim PLS As Long 'position of last slash
Dim pd As Long 'position of dot before exension
Dim strFile As String

On Error GoTo ERROROUT

FPL = Len(strFullPath)
PLS = InStrRev(strFullPath, "\", , vbBinaryCompare)
strFile = Right$(strFullPath, FPL - PLS)

If bExtensionOff = False Then
FileFromPath = strFile
Else
pd = InStr(1, strFile, ".", vbBinaryCompare)
FileFromPath = Left$(strFile, pd - 1)
End If

Exit Function
ERROROUT:

End Function


RBS


"RB Smissaert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The posted code will miss out on add-ins that are open, but not loaded as
> an add-in.
> This code will correct that:
>
> Sub test2()
>
> Dim i As Long
> Dim oProject
> Dim oWB As Workbook
> Dim collWorkbooks As Collection
>
> Set collWorkbooks = New Collection
>
> On Error Resume Next
>
> For Each oProject In Application.VBE.VBProjects
> collWorkbooks.Add FileFromPath(oProject.Filename, False), _
> FileFromPath(oProject.Filename, False)
> Next oProject
>
> For Each oWB In Application.Workbooks
> collWorkbooks.Add FileFromPath(oWB.Name, False), _
> FileFromPath(oWB.Name, False)
> Next oWB
>
> For i = 1 To collWorkbooks.Count
> MsgBox collWorkbooks(i)
> Next i
>
> End Sub
>
>
> RBS
>
>
> "DaveO" <(E-Mail Removed)> wrote in message
> news:68adf48f-dc4b-4fc5-b78b-(E-Mail Removed)...
>> That's what I was looking for, thanks!

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list Workbooks associated with VBA Code. u473 Microsoft Excel Programming 1 26th Nov 2008 08:15 PM
vba code to open workbooks Rebecca1 Microsoft Excel Worksheet Functions 3 5th Mar 2008 05:15 PM
List of open workbooks =?Utf-8?B?YW5hbWFyaWUzMA==?= Microsoft Excel Programming 1 30th Jul 2007 02:32 PM
Getting list of open workbooks lance-news@augustmail.com Microsoft Excel Programming 7 26th Nov 2003 09:09 PM
Re: List Open Workbooks in VBA Chip Pearson Microsoft Excel Programming 1 17th Nov 2003 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.