[VBA Excel] Test If Folder Is Empty

Solved
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. Moderator
    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
    1. It seems to be working, thank you very much!!!
      1