Open Excel file

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)
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top