Forum Discussion
Thisworkbook.Fullname - determine local path with VBA
The only current reply by @NikolinoDE contains some misleading information.
There is no way to get the local path of a OneDrive/Sharpoint synchronized Excel file by using a Scripting.FileSystemObject in VBA.
Addressing your first question
The code you provided,
localFullFileName = fso.GetAbsolutePathName(Application.ActiveWorkbook.Name)
does nothing else than append whatever string the expression in the bracket returns, in your case the name of the active workbook, to the path the current shell environment is set to, which is the path returned by the https://learn.microsoft.com/en-gb/office/vba/language/reference/user-interface-help/curdir-function. This means, your code is equivalent to
localFullFileName = CurDir & ActiveWorkbook.Name
Unfortunately, CurDir is NOT meant to return the path of the active workbook and will not always do so. More information on this can be found https://stackoverflow.com/a/19824472/12287457.
The code in @NikolinoDE's answer also does nothing to localize a path returned by VBA in the case of a OneDrive/SharePoint synchronized file. It only removes the file name, so the last part of the link returned by ThisWorkbook.FullName. It is therefore equivalent to
ThisWorkbook.Path
which will still return a URL in the OneDrive/SharePoint case.
Regarding your second question
It is possible to get the local path using other means, and https://stackoverflow.com/a/73577057/12287457 describes the best option for how this is currently possible, however, it is not what I would describe as a more direct way from Microsoft.
There is indeed a more direct way from Microsoft and it is described in https://stackoverflow.com/a/75751584/12287457. Still, I would strongly discourage anyone from using it as it relies on UI automation and is much less reliable than the https://stackoverflow.com/a/73577057/12287457 I linked.
- Hoang_Dung_4357Feb 28, 2024Copper Contributorthank so much, i'm looking for this.