Open Excel file

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

I have a sub in Access that sucks data out of excel files based on a
path and filename in each record.
If the path or filename are wrong and the Open statement not find the
file I get a info message that says

"c:\temp\filename.xls" can not be found. Check your spelling and try
again." It has an ok button to dismiss it.

How can I trap this "error" or result so I can just skip to the next
record? It does not come up as an error so I can't handle it that way.
Ideally I would like to keep track of which ones it cant find but that
should be easy if I can figure out how to intersept the info message.


Set xlsApp = CreateObject("Excel.application")
Set wb = xlsApp.Workbooks.Open(Path & Filename, , True)
 
If Len(Dir(Path & Filename)) > 0 Then
Set xlsApp = CreateObject("Excel.application")
Set wb = xlsApp.Workbooks.Open(Path & Filename, , True)
Else
MsgBox Path & Filename & " does not exist."
End If
 
Back
Top