[VBA Excel] Test If Folder Is Empty

Solved
Saessen Posted messages 2 Status Member -  
Saessen Posted messages 2 Status Member -
Hello,

I have a problem with Microsoft Excel 2002 (operating system Windows 2000).

Here is the context:

I created a VBA macro in Excel for my work whose purpose is (in summary) to retrieve and sort data coming from other files using various tests.

The macro works correctly, except when one of the folders containing the files to be tested is empty. The macro crashes in that case.

The solution: create a test command to check if the folder in question is empty or not. However, I don't know how to do that... :-S

Would you be extremely kind to help me please...? Thank you in advance.
Configuration: Windows 2000 Internet Explorer 6.0

2 answers

  1. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
     
    Hello,

    rep = "c:\directory\" Set fs = Application.FileSearch With fs .LookIn = rep .Filename = "*.*" If .Execute > 0 Then MsgBox "There are " & .FoundFiles.Count & " files" Else MsgBox "The directory is empty" End If End With


    --
    lami20j
    3
  2. Saessen Posted messages 2 Status Member 1
     
    It seems to be working, thank you very much!!!
    1