
This is achievable. A detail answer here: https://stackoverflow.com/a/73577057/8488913
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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!
This is achievable. A detail answer here: https://stackoverflow.com/a/73577057/8488913
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 Excel
Hope 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.
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