Forum Discussion
easperhe
Jun 02, 2021Copper Contributor
ActiveWorkbook.Path in Excel VBA returning all lowercase
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?
1 Reply
Sort By
- easperheCopper Contributor
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