Hello,
My excel application contains two workbooks, the second one directly created before running the code above.![]()
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 10) Dim i As Integer For i = 1 To Application.Workbooks.Count If InStr(Application.Workbooks.Item(i).Name, "report") > 0 Then Application.Workbooks.Item(i).Activate Dim aSheet As Worksheet Set aSheet = Application.Workbooks.Item(i).Sheets(1) Exit For End If Next i Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
If I set a breakpoint before the for-loop and then execute the code, everything works fine. By executing the code in an automated manner, vba does not execute the code inside the if-statement.
Why vba does not find the second workbook, it surely exists.
Thank you very much!
Lloyd











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks