View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Brite Brite is offline
external usenet poster
 
Posts: 11
Default Open File - Need an warning to appear if file cannnot be found

You guys are the best! Thanks!

"David G" wrote:

On Apr 17, 12:26 pm, Mike H wrote:
one way:-

Sub filefile()
On Error GoTo errorroutine
Workbooks.Open Filename:="C:\test.xls"
MyVal = Application.Workbooks("test.xls").Sheets("Sheet1") .Range("A1").Value
Workbooks("test.xls").Close SaveChanges:=False
Exit Sub
errorroutine:
msg = "File not found"
MsgBox msg
End Sub

Mike


You should probably reset On Error after the file has been opened.
Don't want false errors coming up.
Add "On Error Goto 0" after the Workbooks.Open line.

David G