ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Directory and File Detection (https://www.excelbanter.com/excel-discussion-misc-queries/204278-directory-file-detection.html)

Varne

Directory and File Detection
 
Hi

Can I have help on this please?

I set up files 'Hours' and 'Rate' under each directories 'Jan' to 'Dec'
under directory Lee. I do not want him(Lee) to add a 13th directory under
Lee.

If he does create a 3rd file or 13th directory how can I spot it through VBA
codes?

Thank You.

M Varnendra

joel

Directory and File Detection
 

Folder = "c:\temp\"
Count = 0
FName = dir(Folder & "*.*")
Do while FName < ""
Count = Count + 1
FName = dir()
loop

"Varne" wrote:

Hi

Can I have help on this please?

I set up files 'Hours' and 'Rate' under each directories 'Jan' to 'Dec'
under directory Lee. I do not want him(Lee) to add a 13th directory under
Lee.

If he does create a 3rd file or 13th directory how can I spot it through VBA
codes?

Thank You.

M Varnendra


Varne

Directory and File Detection
 
Hi

Can someone complete what Joes says or provide me with new codes please?

Thanks.

"Joel" wrote:


Folder = "c:\temp\"
Count = 0
FName = dir(Folder & "*.*")
Do while FName < ""
Count = Count + 1
FName = dir()
loop

"Varne" wrote:

Hi

Can I have help on this please?

I set up files 'Hours' and 'Rate' under each directories 'Jan' to 'Dec'
under directory Lee. I do not want him(Lee) to add a 13th directory under
Lee.

If he does create a 3rd file or 13th directory how can I spot it through VBA
codes?

Thank You.

M Varnendra


joel

Directory and File Detection
 
try this code

Sub Macro1()

Set fso = CreateObject _
("Scripting.FileSystemObject")

LeeFolder = "c:\temp"

Set Folder = _
fso.GetFolder(LeeFolder)

If Folder.subfolders.Count 0 Then
For Each sf In Folder.subfolders

'check if Folder Name is a month
FoundMonth = False
For MonthNum = 1 To 12
MonthNm = MonthName(MonthNum, abbreviate:=True)
If UCase(MonthNm) = UCase(sf.Name) Then
FoundMonth = True
Exit For
End If
Next MonthNum
If FoundMonth = False Then
MsgBox ("Folder " & sf.Path & " is not a month")
Else
FName = UCase(Dir(sf.Path & "\*.*"))
If FName < "HOURS" And _
FName < "RATE" Then

MsgBox ("Extra File : " & sf.Path & "\" & FName)
End If
End If

Next sf
End If

End Sub


"Varne" wrote:

Hi

Can someone complete what Joes says or provide me with new codes please?

Thanks.

"Joel" wrote:


Folder = "c:\temp\"
Count = 0
FName = dir(Folder & "*.*")
Do while FName < ""
Count = Count + 1
FName = dir()
loop

"Varne" wrote:

Hi

Can I have help on this please?

I set up files 'Hours' and 'Rate' under each directories 'Jan' to 'Dec'
under directory Lee. I do not want him(Lee) to add a 13th directory under
Lee.

If he does create a 3rd file or 13th directory how can I spot it through VBA
codes?

Thank You.

M Varnendra



All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com