Hello,
I have a function that finds the corresponding file path and partial file name for my input, and then uses Dir() to generate the full, actual file name. Some of my file paths are C://myfilepath/YYYY/file, and some are C://myfilepath/YYYY/MM/file. I am using <YYYY> and <MM> labels, then replacing them with the specific dates needed.
Dir() is not working properly for files that have MM in their file paths (it works fine for files that only have YYYY). Does anyone have any ideas as to why this is, or what I can do to fix it? I have added watches to all my variables and they are populating fine up until the Dir() step.
Thanks in advance!
I have a function that finds the corresponding file path and partial file name for my input, and then uses Dir() to generate the full, actual file name. Some of my file paths are C://myfilepath/YYYY/file, and some are C://myfilepath/YYYY/MM/file. I am using <YYYY> and <MM> labels, then replacing them with the specific dates needed.
Dir() is not working properly for files that have MM in their file paths (it works fine for files that only have YYYY). Does anyone have any ideas as to why this is, or what I can do to fix it? I have added watches to all my variables and they are populating fine up until the Dir() step.
Thanks in advance!
Rich (BB code):
Function GetFileName() As String
Dim strReportName As String
Dim intEndFileList As Integer
Dim n As Integer
Dim strFilePath As String
Dim strFileStart As String
Dim strFileName As String
strReportName = wsForm.Range("F4").Value
intEndFileList = wsFilePath.UsedRange.Rows.Count
'For the chosen report, find the folder path and beginning of file name
For n = 2 To intEndFileList
If wsFilePath.Cells(n, 1).Value = strReportName Then
strFilePath = wsFilePath.Cells(n, 2).Value
strFileStart = wsFilePath.Cells(n, 3).Value
End If
Next n
strFilePath = Replace(strFilePath, "<YYYY>", Year(wsForm.Calendar1.Value))
strFilePath = Replace(strFilePath, "<MM>", Format(Month(wsForm.Calendar1.Value), "00"))
strFileStart = Replace(strFileStart, "<YYYY>", Year(wsForm.Calendar1.Value))
strFileStart = Replace(strFileStart, "<MM>", Format(Month(wsForm.Calendar1.Value), "00"))
strFileName = Dir(strFilePath & strFileStart & "*.csv")
GetFileName = strFilePath & strFileName
End Function