loops - Else If for whether a FileExists() -
i need check whether file produced daily, except on weekends , public/bank holidays, exists. file name each day based on date, need macro next if run on sunday.
i need check whether file exists (it won't on sunday), subtract 1 day date in file name , test whether exists 1 time again , go on loop until finds file exist.
i have got of code far, struggling loop part:
dim integer dim yday date dim ydayyear integer dim ydaymonth integer dim ydayday integer dim copypath string dim pastepath string = 1 yday = dateadd("d", -i, date) ydayyear = datepart("yyyy", yday) ydaymonth = datepart("m", yday) ydayday = datepart("d", yday) copypath = "abc\" & ydayyear & ydaymonth & ydayday & ".csv" pastepath = "xyz\" & ydayyear & ydaymonth & ydayday & ".csv" if fileexists(copypath) filecopy source:=copypath, destination:=pastepath else: = + 1
this become stuck. how create rerun if fileexists(copypath) part of code?
maybe while loop:
do while not fileexists(copypath) = +1 yday = dateadd("d", -i, date) ydayyear = datepart("yyyy", yday) ydaymonth = datepart("m", yday) ydayday = datepart("d", yday) copypath = "abc\" & ydayyear & ydaymonth & ydayday & ".csv" pastepath = "xyz\" & ydayyear & ydaymonth & ydayday & ".csv" loop filecopy source:=copypath, destination:=pastepath
loops excel-vba if-statement
No comments:
Post a Comment