Description
GetLocalPath produces an invalid local path containing the full SharePoint URL when a OneDrive Business provider's ClientPolicy*.ini file lacks a DavUrlNamespace tag (or the file is missing/unreadable), resulting in an empty .webPath for that provider.
This causes Dir() to raise Run-time error '52': Bad file name or number.
Steps to reproduce
- Have a SharePoint-synced workbook where the corresponding
ClientPolicy.ini (or ClientPolicy_*.ini) does not contain a DavUrlNamespace entry
- Call
GetLocalPath(ActiveWorkbook.Path) where the path is a SharePoint URL
Expected result
A valid local path like:
C:\Users\JDoe\OneDrive - Contoso\Shared Documents\Projects\2025\Data
Actual result
C:\Users\JDoe\OneDrive - Contoso\https:\contoso.sharepoint.com\sites\TeamSite\Shared Documents\Projects\2025\Data
Root cause
Two issues:
1. StrCompLeft returns 0 (match) when s2 is empty.
When .webPath is "", the comparison StrCompLeft(odWebPath, "", vbTextCompare) evaluates as:
StrComp(Left$(odWebPath, Len("")), "") → StrComp("", "") → 0 ' Match!
This means a provider with an empty webPath will match any URL input.
2. AddBusinessProviders does not validate tempURL before adding.
The canAdd guard only checks LenB(tempMount) > 0 but not LenB(tempURL) > 0, so providers with empty web paths are added to the cache.
Suggested fix
In StrCompLeft, add an early exit when either string is empty:
Private Function StrCompLeft(ByRef s1 As String _
, ByRef s2 As String _
, ByVal compareMethod As VbCompareMethod) As Long
If Len(s1) = 0 Or Len(s2) = 0 Then
StrCompLeft = -CLng(Len(s1) = 0) + CLng(Len(s2) = 0)
Exit Function
End If
If Len(s1) > Len(s2) Then
StrCompLeft = StrComp(Left$(s1, Len(s2)), s2, compareMethod)
Else
StrCompLeft = StrComp(s1, Left$(s2, Len(s1)), compareMethod)
End If
End Function
In AddBusinessProviders, change:
to:
If canAdd And LenB(tempURL) > 0 Then
Environment
- Windows 11, Excel (Desktop)
- OneDrive for Business syncing SharePoint libraries
ActiveWorkbook.Path returns a https:// SharePoint URL
Note: This bug report and suggested fix were generated with AI assistance (Claude).
Description
GetLocalPathproduces an invalid local path containing the full SharePoint URL when a OneDrive Business provider'sClientPolicy*.inifile lacks aDavUrlNamespacetag (or the file is missing/unreadable), resulting in an empty.webPathfor that provider.This causes
Dir()to raise Run-time error '52': Bad file name or number.Steps to reproduce
ClientPolicy.ini(orClientPolicy_*.ini) does not contain aDavUrlNamespaceentryGetLocalPath(ActiveWorkbook.Path)where the path is a SharePoint URLExpected result
A valid local path like:
Actual result
Root cause
Two issues:
1.
StrCompLeftreturns0(match) whens2is empty.When
.webPathis"", the comparisonStrCompLeft(odWebPath, "", vbTextCompare)evaluates as:This means a provider with an empty
webPathwill match any URL input.2.
AddBusinessProvidersdoes not validatetempURLbefore adding.The
canAddguard only checksLenB(tempMount) > 0but notLenB(tempURL) > 0, so providers with empty web paths are added to the cache.Suggested fix
In
StrCompLeft, add an early exit when either string is empty:In
AddBusinessProviders, change:to:
Environment
ActiveWorkbook.Pathreturns ahttps://SharePoint URLNote: This bug report and suggested fix were generated with AI assistance (Claude).