Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code:
It's purpose is to access a directory (srcpath) and check whether a file (srcfile) exists within it.
Disregard the asterisk as I've placed it here only for reference purposes.
The file could be any one of three file names, the difference being in the placeholder occupied by the asterisk.
For example, the file name could be "May-24 (Fri) Schedule_3.xlsx", "May-24 (Fri) Schedule_5.xlsx" or "May-24 (Fri) Schedule_6.xlsx"
So, I need this code to recognize that if it identifies with any of these variations (will only be one variation), that the file exists.
I'm not sure what adaptation needs to be made to allow this? I could run an individual test for each variation, but I feel the task can be done more efficiently.
Code:
Sub cheese()
Stop
sdate = 43609 'May 24 2019
EDate = 43757 'Oct 20 2019
Days = 148
For lp = sdate To EDate
t_mon = Format(lp, "mmm")
t_day = Day(lp)
t_dayy = Format(lp, "ddd")
tar_str = t_mon & "-" & t_day & " (" & t_dayy & ") Schedule_*"
srcfile = tar_str
strFileName = srcpath & srcfile
strFileExists = Dir(strFileName)
If strFileExists = "" Then
MsgBox "The selected file doesn't exist"
Else
MsgBox "The selected file exists"
End If
lp = lp + 1
Next lp
End Sub
It's purpose is to access a directory (srcpath) and check whether a file (srcfile) exists within it.
Disregard the asterisk as I've placed it here only for reference purposes.
The file could be any one of three file names, the difference being in the placeholder occupied by the asterisk.
For example, the file name could be "May-24 (Fri) Schedule_3.xlsx", "May-24 (Fri) Schedule_5.xlsx" or "May-24 (Fri) Schedule_6.xlsx"
So, I need this code to recognize that if it identifies with any of these variations (will only be one variation), that the file exists.
I'm not sure what adaptation needs to be made to allow this? I could run an individual test for each variation, but I feel the task can be done more efficiently.
Last edited: