cristianbuse / VBA-FileTools

Useful methods for interacting with the file system
MIT License
87 stars 25 forks source link

GetLocalPath fails if space is represented as %20 in path #22

Closed thacht closed 6 months ago

thacht commented 6 months ago

I have a Word document in OneDrive where the folder name includes a space. Word VBA .Path returns the http path where the space is replaced by %20 such as:

https://sp-cloud.abc.org/sites/MyTestSite/Shared%20Documents/Plan_Operations/test

and GetLocalPath(activedocument.path) returns empty.

Word VBA .FullName returns the http path including the space and GetLocalPath returns the local drive path. Excel VBA .Path returns the http path including the space and GetLocalPath returns the local drive path.

cristianbuse commented 6 months ago

Hi @thacht ,

Thanks for the feedback!

I can confirm that ThisDocument.Path in Word encodes spaces to %20. I haven't noticed this as I am mainly an Excel user and there is indeed no problem in Excel.

All I had to do was to add extra logic for decoding such encoded URLs. Please let me know if it works fine for you! Thanks!

cristianbuse commented 6 months ago

I actually pushed a new commit and removed the implicit URL decoding. There could be folders or files that have something like %20 in the name but that does not mean it's an encoded space. it could legitimely be correct name.

Please use GetLocalPath(DecodeURL(ActiveDocument.Path)). This is cleaner than decoding implicitly and causing issues elsewhere. Thanks!

thacht commented 6 months ago

Thank you for the speedy fix!