Word VBA:使用SharePoint同步文件夹时是否有可能获得本地路径而不是远程路径?

时间:2019-09-03 08:57:34

标签: vba sharepoint ms-word

我有以下问题: 我的脚本包含一个函数,该函数可以验证一个或两个文件是否已更新。因此,我必须使用这些文件以及实际路径。问题是这些文件保存在与SharePoint同步的文件夹中。当我使用例如ActiveDocument.Path,此函数返回文件的远程路径,而不是本地路径。问题是我需要本地的。

“ LucasHol”在此处https://social.msdn.microsoft.com/Forums/office/en-US/1331519b-1dd1-4aa0-8f4f-0453e1647f57/how-to-get-physical-path-instead-of-url-onedrive?forum=officegeneral发布了“ Onedrive”解决方案。 此解决方案与OneDrive搭配使用效果很好,但从逻辑上讲,与SharePoint不兼容。我无法采用此代码来与SharePoint一起使用。

代码:

Private Function GetDocLocalPath(doc As Document) As String
'return the local path for doc, which is either already a local document or a document on OneDrive
Const strcOneDrivePart As String = "https://d.docs.live.net/"
Dim strRetVal As String, bytSlashPos As Byte

    strRetVal = doc.path & "\"
    If Left(LCase(doc.path), Len(strcOneDrivePart)) = strcOneDrivePart Then 'yep, it's the OneDrive path
        'locate and remove the "remote part"
        bytSlashPos = InStr(Len(strcOneDrivePart) + 1, strRetVal, "/")
        strRetVal = Mid(doc.path, bytSlashPos)
        'read the "local part" from the registry and concatenate
        strRetVal = System.PrivateProfileString("", "HKEY_CURRENT_USER\Environment", "OneDrive") & strRetVal
        strRetVal = Replace(strRetVal, "/", "\") & "\" 'slashes in the right direction
        strRetVal = Replace(strRetVal, "%20", " ") 'a space is a space once more
    End If
    GetDocLocalPath = strRetVal

End Function

使用SharePoint同步文件夹时是否可以获取本地路径而不是远程路径?

0 个答案:

没有答案