ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error trap on Workbooks.Open (https://www.excelbanter.com/excel-programming/367797-error-trap-workbooks-open.html)

Barb Reinhardt

Error trap on Workbooks.Open
 
I have a for next loop with the following in it.

For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
aWS.Range("H" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
aWS.Range("I" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Creation Date").Value
aWS.Range("J" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Save Time").Value
oWB.Close SaveChanges:=False
aWB.Save
Next i
It works UNTIL the workbook doesn't exist. What do I need to add for error
trapping?

Thanks,
Barb Reinhardt


Dave Peterson

Error trap on Workbooks.Open
 
set oWb = nothing
on error resume next
set owb = workbooks.open(....)
on error goto 0

if owb is nothing then
'it didn't open--error indicator or what
else
'do your work
end if



Barb Reinhardt wrote:

I have a for next loop with the following in it.

For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
aWS.Range("H" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
aWS.Range("I" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Creation Date").Value
aWS.Range("J" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Save Time").Value
oWB.Close SaveChanges:=False
aWB.Save
Next i
It works UNTIL the workbook doesn't exist. What do I need to add for error
trapping?

Thanks,
Barb Reinhardt


--

Dave Peterson


All times are GMT +1. The time now is 01:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com