ActiveWorkbook.Path in Excel VBA returning all lowercase

%3CLINGO-SUB%20id%3D%22lingo-sub-2406707%22%20slang%3D%22en-US%22%3EActiveWorkbook.Path%20in%20Excel%20VBA%20returning%20all%20lowercase%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2406707%22%20slang%3D%22en-US%22%3E%3CP%3EWhen%20I%20open%20a%20blank%20excel%20workbook%20and%20save%20it%20to%20%22C%3A%5CTestPath%5CTestPath.xlsx%22%2C%20the%20following%20command%20in%20Excel%20VBA%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eaaa%20%3D%20ActiveWorkbook.Path%3C%2FP%3E%3CP%3Ereturns%20%22C%3A%5CTestPath%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20after%20I%20close%20the%20file%20and%20reopen%2C%20the%20same%20command%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eaaa%20%3D%20ActiveWorkbook.Path%3C%2FP%3E%3CP%3Ereturns%20%22c%3A%5Ctestpath%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20behavior%20seemed%20to%20change%20after%20updating%20Office%20365.%20Why%20would%20saving%20the%20file%20alter%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2406707%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

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

@easperhe 

 

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