excel vba - VBA - Get the Second-Last modified file (FSO) without built-in functions -


i'm trying 1 before last modified file in folder using excel vba, have managed last modified file, couldn't second one. herein below code used last modified file, without using system functions or built-in function.

sub lastfilemodified()      dim fso new scripting.filesystemobject     dim fill scripting.file       dim integer     dim forstep integer      dim arr() variant      redim arr(fso.getfolder("c:\users\shahim\desktop\xxxx").files.count - 1, 1) variant    = 0  each fill in fso.getfolder("c:\users\shahim\desktop\xxxx").files      arr(i, 0) = fill.name     arr(i, 1) = cdbl(fill.datelastmodified)      = + 1  next fill   dim filename string dim initializer double  initializer = arr(0, 1)  forstep = lbound(arr) ubound(arr)           if arr(forstep, 1) > initializer          initializer = arr(forstep, 1)         filename = arr(forstep, 0)          end if    next forstep  debug.print filename  erase arr  end sub 

sub secodlastmodified()      const fldr_path string = "c:\test"      dim long, j long, filearr() string, maxfiles long     dim fso variant, fldr variant, f variant, l1 string, l2 string      set fso = createobject("scripting.filesystemobject")     set fldr = fso.getfolder(fldr_path)     maxfiles = fldr.files.count     redim filearr(1 maxfiles, 1 2)      = 1     each f in fldr.files         filearr(i, 1) = f.name         filearr(i, 2) = f.datelastmodified         = + 1     next     = 1 maxfiles         j = + 1 maxfiles             if filearr(j, 2) > filearr(i, 2)                 l1 = filearr(i, 2)                 l2 = filearr(i, 1)                 filearr(i, 2) = filearr(j, 2)                 filearr(i, 1) = filearr(j, 1)                 filearr(j, 2) = l1                 filearr(j, 1) = l2             end if         next     next     msgbox filearr(2, 1) end sub 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -