LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need VB Code Help


Hello,

I need some help writing code that will allow me to determine if a file
exists in a directory, or not. I have actually figured out how I can do
this by specifying a single cell. However, I need to have this go
through multiple rows and return a “yes” or “no” for each row.

The amount of rows in this worksheet can vary, so it would have to be
able to determine how many rows are in the sheet also. So, starting in
cell B8 I have a path with the filename that I want to determine its
existence. In cell G8, I want “yes” or “no” to be displayed (depending
on whether the file exists or not). I want the program to then move to
the next row and use cell B9 to determine what value will be placed in
cell G9. This would continue until the last row of the sheet is
reached.

The code below will return a “yes” or “no” in cell G8 depending on
whether the file name in cell B8 exists in the directory path in cell
B5.


Function FileThere(FileName As String) As Boolean
FileThere = (Dir(FileName) "")
End Function

Function GetFileName(FullPath As String)
Dim StrFind As String
Do Until Left(StrFind, 1) = "\"
iCount = iCount + 1
StrFind = Right(FullPath, iCount)
If iCount = Len(FullPath) Then Exit Do
Loop
GetFileName = Right(StrFind, Len(StrFind) - 1)
End Function

Sub test1()
FileName = GetFileName(Range("B8").Value)
Path = Range("B5").Value
If FileThere(Path & FileName) Then
Range("G8").Select
ActiveCell.FormulaR1C1 = "Yes"
Else
Range("G8").Select
ActiveCell.FormulaR1C1 = "No"
End If
End Sub

I do not have much experience with VB code, so any assistance with this
would be much appreciated.

Thanks,
Matt


--
mattc
------------------------------------------------------------------------
mattc's Profile: http://www.excelforum.com/member.php...o&userid=29222
View this thread: http://www.excelforum.com/showthread...hreadid=489488

 
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
do anybody have a sample code for executing excel macro from vb code?<eom B Deepak Excel Programming 2 September 30th 05 09:59 AM
run code on opening workbook and apply code to certain sheets Jane Excel Programming 7 August 8th 05 09:15 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM


All times are GMT +1. The time now is 04:12 PM.

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"