Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
JHB JHB is offline
external usenet poster
 
Posts: 30
Default Checking to see if a file exists.

I would like to create a macro that will check to ensure that a file
exists, which will have a material efefct on the steps to be taken
next. I am havintg trouble finding out how to do this. Can someone
tell me the command argument for an if command that would make the
check, as if:

IF Exists xxx.xls then
else
endif

Thanks a lot.

John Baker
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Checking to see if a file exists.

Dim TestStr as string
teststr = ""
on error resume next
teststr = dir("Yourpathtothefile\yourfilename.ext")
on error goto 0

if teststr = "" then
'not there
else
'yes, it is!
end if



JHB wrote:

I would like to create a macro that will check to ensure that a file
exists, which will have a material efefct on the steps to be taken
next. I am havintg trouble finding out how to do this. Can someone
tell me the command argument for an if command that would make the
check, as if:

IF Exists xxx.xls then
else
endif

Thanks a lot.

John Baker


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,276
Default Checking to see if a file exists.

Hi,
this should get you started:

Function FileExists(fName) As Boolean
' True if exists
On Error GoTo FileExists_Error

FileExists = False

Dim x As String
x = Dir(fName)
If x < "" Then FileExists = True

Exit Function

FileExists_Error:
Select Case Err.Number
Case 52
FileExists = False
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure FileExists "
End Select
End Function


"JHB" wrote:

I would like to create a macro that will check to ensure that a file
exists, which will have a material efefct on the steps to be taken
next. I am havintg trouble finding out how to do this. Can someone
tell me the command argument for an if command that would make the
check, as if:

IF Exists xxx.xls then
else
endif

Thanks a lot.

John Baker

  #4   Report Post  
Posted to microsoft.public.excel.misc
JHB JHB is offline
external usenet poster
 
Posts: 30
Default Checking to see if a file exists.

On Aug 5, 9:29*am, Eduardo wrote:
Hi,
this should get you started:

Function FileExists(fName) As Boolean
' True if exists
* * On Error GoTo FileExists_Error

* * FileExists = False

* * Dim x As String
* * x = Dir(fName)
* * If x < "" Then FileExists = True

* * *Exit Function

FileExists_Error:
* * Select Case Err.Number
* * Case 52
* * * * FileExists = False
* * Case Else
* * * * MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure FileExists "
* * End Select
End Function

"JHB" wrote:
I would like to create a macro that will check to ensure that a file
exists, which will have a material efefct on the steps to be taken
next. I am havintg trouble finding out how to do this. Can someone
tell me the command argument for an if command that would make the
check, as if:


IF Exists xxx.xls then
else
endif


Thanks a lot.


John Baker


Thank you both very much. I am a neophyte, and these answers are a
great help!

John Baker
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
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
File Exists Formula El Bee Excel Worksheet Functions 4 November 9th 06 03:45 PM
Checking if Sheet Exists? [email protected] Excel Discussion (Misc queries) 5 September 1st 06 03:27 PM
Checking to see that a CHART exists prior to running a simple command Anton Excel Discussion (Misc queries) 0 August 29th 06 06:30 AM
File Exists Mike McLellan Excel Discussion (Misc queries) 2 May 4th 06 09:20 AM


All times are GMT +1. The time now is 06:09 AM.

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

About Us

"It's about Microsoft Excel"