I have a VBA code, that may be run either from MS Access or Excel application.
In a part of the code (shown below), I have to find the application file directory as default, to save a CSV file.
The code runs in Excel without any error, but in MS Access, the compiler complains about <Application.ThisWorkbook.Path> and stops there.
what is wrong with the code? I there any other way to find the file path workable for both MS Access and Excel??
If CSVpath = vbNullString Then
Select Case Application.Name '' system in which the code is running from
Case Is = "Microsoft Excel" '' it raises an error in MS Access
CSVpath = Application.ThisWorkbook.Path + "\DataSet_" + CStr(Format(Now(), "YYYY-MM-DD.HH.MM.SS")) + ".csv"
Case Is = "Microsoft Access"
CSVpath = Application.CurrentProject.Path + "\DataSet_" + CStr(Format(Now(), "YYYY-MM-DD.HH.MM.SS")) + ".csv"
Case Else
CSVpath = ""
End Select
End If