Hi there
I have code to loop through all open workbooks to see if a file is open. I've been using this code for years and it works great. The target file changes it's name every month, so we use look for a constant word in the file name to locate it.
NOW, however, if the file ISN'T found within all the open books, I want the code to identify this too. (As I will make a pop-up message that the file isn't open and then code to go open the folder on our LAN... don't need help with this part). JUST can't seem to get it to loop through the open books to determine out of ALL the books, it isn't there.. keeps stopping at the first book that doesn't match and says, "Yup! Not found!" even if the file is open!
Here is my current code to FIND it:
Thoughts for a simple solution?
I have code to loop through all open workbooks to see if a file is open. I've been using this code for years and it works great. The target file changes it's name every month, so we use look for a constant word in the file name to locate it.
NOW, however, if the file ISN'T found within all the open books, I want the code to identify this too. (As I will make a pop-up message that the file isn't open and then code to go open the folder on our LAN... don't need help with this part). JUST can't seem to get it to loop through the open books to determine out of ALL the books, it isn't there.. keeps stopping at the first book that doesn't match and says, "Yup! Not found!" even if the file is open!
Here is my current code to FIND it:
Code:
' 1) loop through open books and look for the destination book (name contains "Dump")
For iIdx = 1 To Workbooks.Count 'assumes won't have >30000 workbooks open so idx, interger variable takes up less space wb variable
If InStr(1, UCase(Workbooks(iIdx).Name), "DUMP") > 0 Then
Set wbSource = Workbooks(iIdx) 'referencing wb within index of workbooks
Set wsSource = wbSource.Sheets(1)
On Error Resume Next 'if an error is generated, don't pop up messages to the user, just resume next, keep on trucking
On Error GoTo 0 'do regular error junk, set
Exit For 'will take the first wb with "process", once found it works and exits
End If
Next iIdx
Thoughts for a simple solution?