Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open File - Need an warning to appear if file cannnot be found
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! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open File - Need an warning to appear if file cannnot be found
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Saved *.csv file gives SYLK file type warning upon Excel 2003 open | Excel Discussion (Misc queries) | |||
Macro warning pops up at file open | Excel Discussion (Misc queries) | |||
Close an Excel file if is found it open. | Excel Programming | |||
File Not Found menu pops up after I open a file | Excel Discussion (Misc queries) | |||
Excel file already open warning | Setting up and Configuration of Excel |