hi all,
How can i get the name of all opened (excel) file . I have to list the name of all file and check whether the the file which is required by program is open or not.what should be its vba code to do this?
thanks in advance
hi all,
How can i get the name of all opened (excel) file . I have to list the name of all file and check whether the the file which is required by program is open or not.what should be its vba code to do this?
thanks in advance
Last edited by princ_wns; 04-05-2012 at 09:59 PM.
Hi
This is not the answer to your thread title, but give this a try
Code:Dim wbkOpened As Workbook On Error Resume Next Set wbkOpened = Workbooks("YourWorkbookName.xls") On Error GoTo 0 If wbkOpened Is Nothing Then Set wbkOpened = Workbooks.Open("WorkbookFullName") End If
Cheers !
Excel Range to BBCode Table
Use Social Networking Tools If You Like the Answers !
Message to Cross Posters
@ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)
If you to check if a particular file you are looking for is currently open, use this function
and call it like thisCode:Function IsBookOpen(strNameOfFile As String) As Boolean Dim wbk As Workbook For Each wbk In Application.Workbooks If InStr(1, wbk.Name, strNameOfFile) Then IsBookOpen = True: Exit For End If Next wbk End Function
If you want a list of all open workbooks, try modifying by taking out the if condition and printing out the names of each workbook like for exampleCode:IsBookOpen "MyBook.xlsx"
Code:Msgbox wbk.Name
A dream is not something you see when you are asleep, but something you strive for when you are awake.
It's usually a bad idea to say that something can't be done.
The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve
Join us at Facebook
Thanks to all for their reply, the last reply is exactly same , i was looking for.
How would you say my code is not working the same way you were looking for ?
BTW, you could use as a function as well.
and call likeCode:Function IsWorkbookOpened(ByVal WorkbookName As String) As Boolean Dim wbkOpened As Workbook On Error Resume Next Set wbkOpened = Workbooks(CStr(WorkbookName)) On Error GoTo 0 IsWorkbookOpened = Not wbkOpened Is Nothing End Function
Code:MsgBox IsWorkbookOpened("MyWorkbook.xlsx")
Cheers !
Excel Range to BBCode Table
Use Social Networking Tools If You Like the Answers !
Message to Cross Posters
@ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)
Hi princ_wns
Here is a code which gives the List of All Open Workbook Files in the same instance.
Code:Sub ListOpenBooks() 'lists each book that's OPEN Dim wb As Workbook For Each wb In Application.Workbooks MsgBox wb.Name Next wb End Sub
Bookmarks