
Createfile error 32 when trying set file time code#
Out of Memory when trying to run VBA code

' In theory, the file could go from not-in-use to in-use between the check above and the delete below. Msgbox("Attempted to delete file at:" & filenames(1, OldestIndex) & " but file may be open elsewhere or by another user.") But should work nonetheless.'įor fileindex = lbound(filenames,2) to ubound(filenames,2) ' Might be better to store below in dictionary - or any key-value/associative structure. Oldest = filenames(2,1) ' Initialise with first value' VBA.Format$(Now, "m-d-yyyy hhmmss AM/PM") & ".xlsm") VBA.Replace(ThisWorkbook.Name, ".xlsm", "_copy_" & _

Redim preserve filenames(1 to 2, 1 to fileindex) Redim filenames(1 to 2, 1 to 1000) ' 1000 = magic number, change if needed.'įilename(1, fileindex) = folderPath & filenameįilenames(2, fileindex) = filedatetime(Filename(1, fileindex)) Option ExplicitįolderPath = dir$("R:\Groups\Finance\Ops Finance\Reporting\F18 Cost Analysis\Standard Costing\Std Cost Variances\Variance Master Back-Ups\", vbdirectory)Įlseif strcomp(right(folderPath, 1),"\", vbbinarycompare) 0 then ' this might be unnecessary, depends if dir() on vbdirectory returns \ at end or not, cannot remember or test' The below is not that different from your code, but might do what you need.
