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

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

"Brite" wrote:

I was wondering how i would go about adding a warning message that says "File
cannot be found" to the following code if the the test.xls file cannot be
found?

Sub filefile
Workbooks.Open FileName:="C:\test\test.xls"
MyVal = Application.Workbooks("test.xls").Sheets("Sheet1") .Range("A1").Value
Workbooks("test.xls").Close SaveChanges:=False
End Sub

thanks in advance for your help!