Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default does file exist

Hi

I have a list of files, with the directory path from cells a1 to a10
and want to check to see if any do not exist. I would like the file
names assigned to an array in vba, check them off and if one does not
exist stop the code running with an error message.

Here is what I have works well for one file.


Sub test2()

Dim sName As String

sName = Range("A2").Value
If Dir(sName) < "" Then
'do nothing in this case
Else
MsgBox "file Not found, stop the code at this point"
'file was found
End If

End Sub

Thanks

Chad

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default does file exist

I'm not sure I'd use an array but to each his own
Dim sNames() as String
Dim cnt as Long
Dim lRow as Long
Set lRow = Range("A" & Rows.Count).End(xlUp).Row
For cnt = 2 to lRow
ReDim Preserve sNames(cnt - 2)
sNames(cnt - 2) = Range("A" & cnt)
If Dir(sName(cnt - 2)) < "" Then
MsgBox "Error File Not Found"
Exit Sub
End If
Next

HTH

Charles Chickering

Chad wrote:
Hi

I have a list of files, with the directory path from cells a1 to a10
and want to check to see if any do not exist. I would like the file
names assigned to an array in vba, check them off and if one does not
exist stop the code running with an error message.

Here is what I have works well for one file.


Sub test2()

Dim sName As String

sName = Range("A2").Value
If Dir(sName) < "" Then
'do nothing in this case
Else
MsgBox "file Not found, stop the code at this point"
'file was found
End If

End Sub

Thanks

Chad


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default does file exist

Sub test2()
Dim cell as Range
Dim sName As String
for each cell in Range("A1:A10")
sName = cell.Value
If Dir(sName) = "" Then
MsgBox "file Not found, stop the code at this point"
Exit for
End If
Next cell
End Sub


--
Regards,
Tom Ogilvy


"Chad" wrote in message
ups.com...
Hi

I have a list of files, with the directory path from cells a1 to a10
and want to check to see if any do not exist. I would like the file
names assigned to an array in vba, check them off and if one does not
exist stop the code running with an error message.

Here is what I have works well for one file.


Sub test2()

Dim sName As String

sName = Range("A2").Value
If Dir(sName) < "" Then
'do nothing in this case
Else
MsgBox "file Not found, stop the code at this point"
'file was found
End If

End Sub

Thanks

Chad



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default does file exist

Yep

Exactly what I was looking for. Thank you both very much for your
help.

Take care

Chad

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
Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it. Tintin92 Excel Programming 3 March 11th 06 06:45 PM
Does File Exist ceemo[_21_] Excel Programming 2 August 26th 05 04:44 PM
File does not exist Judd Jones[_2_] Excel Programming 2 January 14th 05 03:18 PM
Does file exist? ianripping[_81_] Excel Programming 4 July 26th 04 12:48 PM
does a file exist? Keith Willshaw Excel Programming 0 September 10th 03 04:42 PM


All times are GMT +1. The time now is 05:33 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"