Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
WORKBOOKS.OPEN (URL) - How to trap a connection-lost/ timeout erro BHARATH RAJAMANI Excel Programming 3 September 18th 04 02:37 PM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
error on oXL.Workbooks.Open arieribbens Excel Programming 3 April 26th 04 10:09 AM


All times are GMT +1. The time now is 01:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"