This is achievable. A detail answer here: https://stackoverflow.com/a/73577057/8488913
Get Excel File local absolute path instead of OneDrive Url
Hi everyone!
I am having an issue with finding the local path of my Excel file on disk when synced with OneDrive.
Here is the context: I have an Excel file on my local machine that is also synced with OneDrive. When I try the formula CELL("filename") in Excel I get the https link returned instead of the local path (C:/.../).
I need to access the local path information from my Visual Basic code. What I have is a Microsoft.Office.Interop.Excel._Workbook object. Whenever I try to return Microsoft.Office.Interop.Excel._Workbook.Path I get the https link to OneDrive instead of the local path of my currently opened Workbook. Does there exist an API call to Excel that would return me the local path instead of the URL? I saw solutions involving writing some code to recover the local path from the URL but I do not want to do that to prevent any problems in the future. Or is there an alternative to recover the information I want?
Thank you for your help!
Microsoft 365 and Office OneDrive For business Windows
Microsoft 365 and Office Excel For business Windows
Developer technologies VB
3 answers
Sort by: Most helpful
-
-
Viki Ji_MSFT 4,471 Reputation points
2021-11-18T02:54:31.047+00:00 Hi @Struggling ,
Welcome to Q&A forum!This is because the files synced to OneDrive are online files that are synced in real time. According to my test, I suggest you click on the OneDrive icon and go to Help & Settings>Settings>Office to uncheck the "Use Office application to sync Office files that I open" option to check this issue.
However, since VBA is out of our support scope, I'm not sure if it will affect the "Microsoft.Office.Interop.Excel._Workbook.Path" in VBA. Thanks for your understanding. If you have any confusion or questions about VBA later, I suggest you go to the following page to seek more professional help.
Build powerful applications for ExcelHope the information is helpful to you. Any updates, pelase let me know.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. -
Excel VBA Diary 0 Reputation points
2023-12-15T10:26:03.39+00:00 If you want a solution not only for OneDrive but also for OneDrive for Buisness, please refer to the following GitHub.
"Resolve the problem of ThisWorkbook.Path returning a URL in OneDrive"
https://github.com/Excel-VBA-Diary/GetThisWorkbookLocalPath