November 28, 2024

Excel VBA: Get local path of file in OneDrive Sync location

I share here an issue you might encounter when using macros with sync'ed files from OneDrive, SharePoint.

Problem Description

If you use an office e.g. Excel file located in a OneDrive or SharePoint locally in its sync'ed location, it is quite cumbersome to get the local PAth where the file is sync'ed on your PC.
(You will much want this if you have VBA Macros in this file.)
Indeed the Workbook.Path property returns the OneDrive or SharePoint URL location (in the Cloud) and not the local directory where the file is stored. See https://techcommunity.microsoft.com/t5/excel/thisworkbook-fullname-determine-local-path-with-vba/m-p/3816000

Solution

I have found this solution that works very well for me:


No comments:

Post a Comment