Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Check File Name Existence in Array

Yes, something like this:

Function bFileExists(ByVal sFile As String) As Boolean
Dim lAttr As Long
On Error Resume Next
lAttr = GetAttr(sFile)
bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0
End Function

Then in your processing Sub something like this:

For i = 0 To UBound(v)
If bFileExists(sPath & v(i)) = False then
Msgbox "This can't work, missing file:" & vbcrlf & _
sPath & v(i)
exit sub
end if
next i


RBS


"Kirk P." wrote in message
...
I've got this code, which works as expected:

Sub ProcessCTSWorkbooks()
Dim bk As Workbook
Dim sPath As String
Dim v As Variant
Dim i As Long
Dim sh As Worksheet

On Error GoTo ErrHandle

sPath = "\\oprdgv1\depart\Finance\_Budget\Current Year ePlanning Loads\"
v = Array("CTS_700_HPP_EPlanning_Load.xls",
"CTS_747_Education_Eplanning_Load.xls", _
"CTS_750_TRS_Eplanning_Load.xls", "CTS_751_CRS_Eplanning_Load.xls", _
"CTS_752_CHD_Eplanning_Load.xls", "CTS_753_NRS_Eplanning_Load.xls", _
"CTS_754_RRS_Eplanning_Load.xls", "CTS_755_BRS_Eplanning_Load.xls", _
"CTS_756_KRS_Eplanning_Load.xls", "CTS_759_MTP_Eplanning_Load.xls", _
"CTS_760_SPR_Eplanning_Load.xls",
"CTS_771_Comprehensive_Cancer_Eplanning_Load.x ls", _
"CTS_772_Pregnancy_Childbirth_Eplanning_Load.x ls",
"CTS_790_Case_Management_Eplanning_Load.xls", _
"CTS_999_OH_Eplanning_Load.xls")
For i = LBound(v) To UBound(v)
Set bk = Workbooks.Open(sPath & v(i), UpdateLinks:=0)
For Each sh In bk.Worksheets
sh.UsedRange.Formula = sh.UsedRange.Value
Next
bk.Close SaveChanges:=True
Next

ErrHandle:
MsgBox "Error #: " & Err.Number & ": " & Err.Description & vbCrLf
Exit Sub

End Sub

Right now, it processes each one as the file is found. Is there a good
way
to check to make sure all the file names in the array actually exist
BEFORE
the processing starts?


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 for existence of a file DKS Excel Programming 4 April 9th 07 08:46 PM
Range existence check DoctorG Excel Programming 6 July 13th 06 04:31 PM
Check for existence CWillis Excel Discussion (Misc queries) 3 May 31st 06 01:20 PM
VBA to check for existence of a DSN GPO Excel Programming 2 May 29th 06 05:22 AM
Check File Existence Catalin[_2_] Excel Programming 5 May 10th 06 10:20 AM


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