Jun 01 2021 09:03 PM
When I open a blank excel workbook and save it to "C:\TestPath\TestPath.xlsx", the following command in Excel VBA
aaa = ActiveWorkbook.Path
returns "C:\TestPath"
But after I close the file and reopen, the same command
aaa = ActiveWorkbook.Path
returns "c:\testpath"
This behavior seemed to change after updating Office 365. Why would saving the file alter this?
Jun 08 2021 03:59 PM
I found a simple work-around to deal with this stupid issue. Note, I believe the issue is related to OneDrive stuff. Nevertheless, the work around is to call the GetPathRealCase function with the all lowercase path returned by .PATH as the argument. Fortunately, the FileSystemObject.GetAbsolutePathName returns the correct, case preserved, path. So any place I was using .Path, e.g. curPath = ActiveWorkbook.Path, I would wrap that with a call to this function, e.g. curPath = GetPathRealCase(ActiveWorkbook.Path)
Public Function GetPathRealCase(curPath As String)
Set fso = New FileSystemObject
GetPathRealCase = fso.GetAbsolutePathName(curPath)
End Function