Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2011, 09:23 AM
SDondeti SDondeti is offline list of Opened excel files Windows XP list of Opened excel files Office 2007
Novice
list of Opened excel files
 
Join Date: Apr 2011
Posts: 7
SDondeti is on a distinguished road
Default list of Opened excel files

Hi,

I got some problem in finding the names of all excel opened files using word VBA.

Following code is working in excel vba but i am not able to do it in word vba. Can some one help me. Thanks in advance.



Dim wb As Workbook
For Each wb In Application.Workbooks
MsgBox wb.Name
Next

Thanks,
SDondeti
Reply With Quote
  #2  
Old 04-13-2011, 03:59 PM
macropod's Avatar
macropod macropod is offline list of Opened excel files Windows 7 32bit list of Opened excel files Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi SDondeti,

Try something along the lines of:
Code:
Sub ListOpenExcelFiles()
Dim ObjXL As Object, xlWkBk, StrWkBks As String
' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next
Set ObjXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
  MsgBox "No Excel Files are open (Excel is not running)"
  Exit Sub
End If
For Each xlWkBk In ObjXL.Workbooks
  StrWkBks = StrWkBks & vbCr & xlWkBk.Name
Next
MsgBox "The following Excel Files are open:" & StrWkBks
Set ObjXL = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-15-2011, 08:31 AM
SDondeti SDondeti is offline list of Opened excel files Windows XP list of Opened excel files Office 2007
Novice
list of Opened excel files
 
Join Date: Apr 2011
Posts: 7
SDondeti is on a distinguished road
Default

Thank you Paul.

Finally i am able to manage instanse create object and able to retrieve the names of all active excel file names.

Thank you.
Reply With Quote
  #4  
Old 02-21-2018, 03:40 PM
goose0701 goose0701 is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 64bit
Novice
 
Join Date: Feb 2018
Posts: 4
goose0701 is on a distinguished road
Default

Hello All!

I know this one is solved, but I didn't want to start a whole new thread for the same issue (pretty close).

I used the code above with a tweak to populate a listbox, but it is only picking up 1 open excel file. it is not doing each.

here is my code:
Code:
Public Sub UserForm_Initialize()
    
Dim ObjXL As Object, xlWkBk, StrWkBks As String

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next
Set ObjXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
  filelist.AddItem ("No Excel Files are open (Excel is not running)")
  Exit Sub
End If
For Each xlWkBk In ObjXL.Workbooks
filelist.AddItem xlWkBk.Name
Next xlWkBk

Set ObjXL = Nothing
    
End Sub
does anyone know where I am going wrong on this one?
Reply With Quote
  #5  
Old 02-21-2018, 05:07 PM
macropod's Avatar
macropod macropod is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code as posted works for me.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 02-23-2018, 10:29 AM
goose0701 goose0701 is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 64bit
Novice
 
Join Date: Feb 2018
Posts: 4
goose0701 is on a distinguished road
Default

No way! Thank you for the quick response macropod! you're the best!

If I have multiple excel docs open, only 1 shows up in my list. I have to close the other docs and reopen the user form in order to get to the one I want.

any ideas if I am running a setting wrong? I have the Excel 14.0 library reference included already.
Reply With Quote
  #7  
Old 02-23-2018, 01:33 PM
macropod's Avatar
macropod macropod is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I said, the code works for me and lists multiple files. No Excel reference is needed, as late binding is used. Perhaps the issue is that your userform has already created its own Excel session and is therefore only finding files running under that session?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 05-10-2018, 02:16 PM
goose0701 goose0701 is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 64bit
Novice
 
Join Date: Feb 2018
Posts: 4
goose0701 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As I said, the code works for me and lists multiple files. No Excel reference is needed, as late binding is used. Perhaps the issue is that your userform has already created its own Excel session and is therefore only finding files running under that session?
Better late than never. I am sorry I haven't had time to mess with this project lately.

So how would my userform create it's own Excel session? This is the only code I have in the UserForm Initialize sub. So I am unsure where to look.
Reply With Quote
  #9  
Old 05-10-2018, 02:25 PM
macropod's Avatar
macropod macropod is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Possible misdirection there - the userform code you posted cannot create a new Excel session. That said, in Excel it's possible to have more than one session running. If that's the situation on your system, the code will only find files open in the Excel session it attaches to (probably the last one started). If you open the Task Manager, you should be able to see how many Excel sessions you have running.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 05-10-2018, 02:49 PM
goose0701 goose0701 is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 64bit
Novice
 
Join Date: Feb 2018
Posts: 4
goose0701 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Possible misdirection there - the userform code you posted cannot create a new Excel session. That said, in Excel it's possible to have more than one session running. If that's the situation on your system, the code will only find files open in the Excel session it attaches to (probably the last one started). If you open the Task Manager, you should be able to see how many Excel sessions you have running.
ahhhh!! that is exactly it. I have them running in separate instances always.

Is there a way around this to show all excel instances?
Reply With Quote
  #11  
Old 05-10-2018, 03:52 PM
macropod's Avatar
macropod macropod is offline list of Opened excel files Windows 7 64bit list of Opened excel files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Not that I am familiar with.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
list of Opened excel files seach an Excel list elements in word document 7ajar Word VBA 5 03-16-2011 12:38 PM
Importing many vcf files in excel shiflerg Excel 0 01-26-2011 09:16 AM
Creating mailing labels from list in excel wordnoob2 Mail Merge 0 12-13-2010 03:46 PM
list of Opened excel files Opening multiple Excel files within the same Excel window. lost9471 Excel 2 05-01-2010 01:57 PM
Creating a Distrubution List from Excel webphotogeek Outlook 0 01-10-2008 11:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft