PC Review


Reply
Thread Tools Rate Thread

Check File Name Existence in Array

 
 
=?Utf-8?B?S2lyayBQLg==?=
Guest
Posts: n/a
 
      6th Jun 2007
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.xls", _
"CTS_772_Pregnancy_Childbirth_Eplanning_Load.xls",
"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 With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      6th Jun 2007

For i = LBound(v) To UBound(v)
if Dir(v(i)) "" Then
MsgBox "Not all present, " & v(i)
Exit For
End If
Next i

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Kirk P." <(E-Mail Removed)> wrote in message
news:3210C138-790A-40CC-8B8D-(E-Mail Removed)...
> 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.xls", _
> "CTS_772_Pregnancy_Childbirth_Eplanning_Load.xls",
> "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 With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      6th Jun 2007
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." <(E-Mail Removed)> wrote in message
news:3210C138-790A-40CC-8B8D-(E-Mail Removed)...
> 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.xls", _
> "CTS_772_Pregnancy_Childbirth_Eplanning_Load.xls",
> "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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check existence of file if file name has a space in it. mc Microsoft Excel Programming 3 30th Sep 2008 07:39 PM
Check for file existence within own site John Microsoft ASP .NET 4 30th Jan 2008 06:42 AM
I need to check for existence of a file on our website in "images"... trint Microsoft C# .NET 3 23rd Apr 2007 05:24 PM
Check for existence of a file =?Utf-8?B?REtT?= Microsoft Excel Programming 4 9th Apr 2007 08:46 PM
Check File Existence =?Utf-8?B?Q2F0YWxpbg==?= Microsoft Excel Programming 5 10th May 2006 10:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:25 AM.