Daily generated new Excel file with data will have the following name: "RawData_today date-time.xlsx", for example: "Report_2017-04-10-10-17-42.xlsx". I'm trying to set a right Path to the file, knowing only the first part of its name and ignoring the time-part?
As was suggested by @ShaiRado and @RobinMackenzie, the following code should work properly:
Dim RawDataPath As String
Dim FolderPath As String
FolderPath = ThisWorkbook.Path & "\"
RawDataPath = FolderPath & "Report" & format(Date, "yyyy-mm-dd") & "*.xlsx"
However, I am still getting the error message, and I think the issue is not in the line above.
I looked for a file using
RawDataPath = Dir$(FolderPath & "Report" & format(Date, "yyyy-mm-dd") & "*.xlsx")
If (Len(RawDataPath) > 0) Then
MsgBox "found " & RawDataPath
End If
Result -> the right file is found. The second part of the code:
'check if the file exists
If FileExists(RawDataPath) = False Then RawDataPath = BrowseForFile("File not found. Please select the file.")
'check if the workbook is open
If Not IsWbOpen(RawDataPath) Then Workbooks.Open RawDataPath
Check if the file exists fails. Run-time error '1004': Sorry, we couldn't find False.xlsx. Is it possible it was moved, renamed or deleted?
I don't undertand why does it look for a False.xlsx? What am I doing wrong?
Any help would be appreciated.