![microsoft onedrive for business library url microsoft onedrive for business library url](https://images.prismic.io/product-website/009aef31-4347-4b92-a8e0-84f850dfab8a_OneDrive-retention-without-retention-policy.png)
If objFSO.FileExist(strOneDriveLocalFilePath) ThenīlnFileExist = True 'that is it - WE GOT ITīlnFileExist = False 'not there try another OneDrive type (personal/business) If objFSO Is Nothing Then Set objFSO = CreateObject("Scripting.FileSystemObject") 'verify if file exist in this location and exit for loop if True StrOneDriveLocalFilePath = strOneDriveLocalPath & strFileEndPath 'this is the final file path on Local drive StrFileEndPath = Replace(strFileEndPath, "/", "\") 'flip slashes from URL type to File path type If Len(strFileEndPath) > 0 Then 'check if path found StrFileEndPath = Mid(strFileURL, i4thSlashPosition, Len(strFileURL) - i4thSlashPosition + 1) 'get the ending file path without pointer in OneDrive I4thSlashPosition = InStr(i4thSlashPosition + 1, strFileURL, "/") 'loop 4 times, looking for "/" after last found ' by replacing "https." with OneDrive local path obtained from registry we can get local file path 'for personal onedrive it looks like "" & file.FullName, _ StrFileEndPath = Mid(strFileURL, iDocumentsPosition, Len(strFileURL) - iDocumentsPosition + 1) 'get the ending file path without pointer in OneDrive
![microsoft onedrive for business library url microsoft onedrive for business library url](https://info.varonis.com/hs-fs/hubfs/Imported_Blog_Media/office-365-file-sharing-tool.jpg)
IDocumentsPosition = InStr(1, strFileURL, "/Documents") + Len("/Documents") 'find "/Documents" position in file URL 'find "/Documents" in string and replace everything before the end with OneDrive local path 'for commercial OneDrive file path seems to be like "" & file.FullName) If strOneDriveLocalPath vbNullString Then StrOneDriveLocalPath = ShellScript.RegRead("HKEY_CURRENT_USER\Environment\" & strRegKeyName) Set ShellScript = CreateObject("WScript.Shell") On Error Resume Next 'invalid or non existin registry keys check would evaluate error Private Function strOneDriveLocalFilePath() As String Simply call it from another sub or function to obtain the file path.
MICROSOFT ONEDRIVE FOR BUSINESS LIBRARY URL CODE
The code checks all instances of OneDrive in the system and verify if file is there. In case your OneDrive folder is not in default location, the code below will allow you to locate the file wherever it is. StrRetVal = Replace(strRetVal, "/", "\") 'slashes in the right direction StrRetVal = RegKeyRead("HKEY_CURRENT_USER\Environment\OneDrive") & strRetVal If Left(LCase(docPath), Len(strcOneDrivePart)) = strcOneDrivePart Then 'yep, it's the OneDrive path Private Function GetDocLocalPath(docPath As String) As String ' This is needed to get the local path, not the one drive path 'if the key cannot be found, the return value is ""įunction RegKeyRead(i_RegKey As String) As String 'reads the value for the registry key i_RegKey (Also notice I did change some slashes stuff for what I wanted returned! Other than that works great! Thank you so much! I was using excel not word, so the registry grabber "System." did not work for me. StrRetVal = Replace(strRetVal, "%20", " ") 'a space is a space once more StrRetVal = Replace(strRetVal, "/", "\") & "\" 'slashes in the right direction StrRetVal = System.PrivateProfileString("", "HKEY_CURRENT_USER\Environment", "OneDrive") & strRetVal 'read the "local part" from the registry and concatenate If Left(LCase(doc.Path), Len(strcOneDrivePart)) = strcOneDrivePart Then 'yep, it's the OneDrive pathīytSlashPos = InStr(Len(strcOneDrivePart) + 1, strRetVal, "/") 'return the local path for doc, which is either already a local document or a document on OneDriveĭim strRetVal As String, bytSlashPos As Byte Private Function GetDocLocalPath(doc As Document) As String I'm using Word 2016 but I'm pretty sure this can be done in Word 2013 and Word 2010 as well. in which case I'll add my reply for anyone who's interested. It's been a while since you posted this so I suppose you don't need an answer any longer.