View Single Post
 
Old 09-30-2021, 07:45 PM
Peterson Peterson is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default How to log info about files while looping through many in a folder

I'm creating a macro that loops through all files in a folder and does stuff if a condition is met.

The user needs a report of any files not revised because the condition wasn't met.

My code is modular: a loop sub calls another sub to test the condition/do the stuff.

I'd like to keep the code modular -- I don't want to modify the loop sub to receive failed-condition info back, and add to an array.

Is it possible to collect data (in an array) in a standalone sub that periodically gets the data from another sub, or do I have to modify my loop sub so that it can collect the data, as it's the only sub continuously running for the duration of the work? Maybe this will help:
Code:
Sub Loop()
      Open a file     
         Call EvaluateAndDoStuff
    Next file
    When no more files, drop array in CollectListOfFailedFiles into text file
End Sub
 
Sub EvaluateAndDoStuff()
    If condition not met Then
       Call CollectListOfFailedFiles(strFile)
    End If
End Sub

Sub CollectListOfFailedFiles(strFile as String)
    Array here that collects list of failed files... 
End Sub
Reply With Quote