i have a folder which contains e.g files abc, poi, krf, lss and i have a button that contains an existing code that iterates through the folder and extract data from each files into the excel sheet.
However despite the data being already extracted to the excel sheet, every time i click the button it will still extract data from each files, i would like to avoid that by saving all the filenames in the folder into an array or other methods THEN whenever i press the button , it will compare the "previous file names" inside the folder, if any changes are done to the folder, e.g new file mmn is added into the folder, it will only do extraction on file "mmn" and skip extraction on the rest of the files that were still in the folder.
e.g my folder now currently has 50 files(all with different names) e.g "abc","mmn","lll", i save these 50 file names and then if i click on my button to extract data, it will check whether my folder had any changes happened to it, e.g if it still contains the 50 files(same name as previous,"abc","mmm","lll") , then don't do any extraction because data already exists in the excel sheet.
however, if the files in the folder changed, e.g a new file named "uio" got added in, then i want to only do extraction on "uio" and add the data below the last row that contains data instead of all the files "abc","mmn","lll" and "uio" .
This is my current code, can anyone please let me know how i can modify it to match my description?
Thank you to everyone.
Option Explicit
Sub LoopFiles()
Dim strFolder As String
Dim strDirRef As String
Dim nFiles As Long, i As Long
Dim strFound() As String
strFolder = "C:UsersDesktopasi"
strDirRef = Dir(strFolder)
Do While Len(strDirRef) > 0
nFiles = nFiles + 1
ReDim Preserve strFound(1 To nFiles)
strFound(nFiles) = strDirRef
strDirRef = Dir
Loop
For i = 1 To nFiles
Debug.Print strFound(i)
Next i
End Sub
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…