Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saved *.csv file gives SYLK file type warning upon Excel 2003 open Tom Excel Discussion (Misc queries) 5 March 19th 08 03:15 PM
Macro warning pops up at file open Texas Tonie[_2_] Excel Discussion (Misc queries) 2 May 3rd 07 06:56 PM
Close an Excel file if is found it open. Chuckles123[_114_] Excel Programming 4 May 7th 06 11:42 AM
File Not Found menu pops up after I open a file Harveytunes Excel Discussion (Misc queries) 3 January 27th 06 07:23 PM
Excel file already open warning binaryben Setting up and Configuration of Excel 0 July 6th 05 12:30 PM


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"