Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2021, 07:45 PM
Peterson Peterson is offline How to log info about files while looping through many in a folder Windows 10 How to log info about files while looping through many in a folder Office 2019
Competent Performer
How to log info about files while looping through many in a folder
 
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
  #2  
Old 10-01-2021, 02:45 PM
Guessed's Avatar
Guessed Guessed is offline How to log info about files while looping through many in a folder Windows 10 How to log info about files while looping through many in a folder Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can keep passing variables across functions but I think it is easier to declare a variable so it can be used by all the sub/functions in the module. This then persists and can be added to or read by any of the subs or functions. This illustrates the concept.
Code:
Option Explicit

Private arr1() As String, sArr As String

Sub TheLoop()
  Dim i As Integer
  sArr = ""       'this empties the string in case the macro was run earlier
  For i = 1 To 10
    TheTest i
  Next i
ThePayout:
  MsgBox sArr
  arr1 = Split(sArr, "|")
End Sub

Sub TheTest(i As Integer)
  If i Mod 2 = 0 Then
    TheLogger i
  End If
End Sub

Sub TheLogger(i As Integer)
  If sArr = "" Then
    sArr = "Item " & i
  Else
    sArr = sArr & "|" & "Item " & i
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-07-2021, 09:14 PM
Peterson Peterson is offline How to log info about files while looping through many in a folder Windows 10 How to log info about files while looping through many in a folder Office 2019
Competent Performer
How to log info about files while looping through many in a folder
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

Hi Andrew -- A belated thank you for your reply and sample code!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through a folder of PDF files and saving them as docx ballpoint Word VBA 5 11-22-2018 05:18 AM
How to log info about files while looping through many in a folder Error 4605 when looping through files in folder and deleting comments Peterson Word VBA 2 04-19-2018 08:45 AM
How to log info about files while looping through many in a folder Open csv files & copy and paste info into master file gbaker Outlook 9 04-22-2016 11:02 PM
VBA Word - Search Within Files Containing A String - Copy Files to New Folder jc491 Word VBA 0 01-09-2016 12:00 PM
How to log info about files while looping through many in a folder Move files from one folder to another obasanla Word 1 09-28-2012 04:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft