1

我对此进行了大量研究并找到了许多帮助站点,但仍然无法理解为什么有时这不起作用。

我正在尝试访问一个共享点站点(对我没有限制)并提取该站点内文件夹中的所有文件。

有时我的路径有效并且它可以做到,有时它不会。我有一种感觉,如果我之前在浏览器上进入过 sharepoint 站点但无法确认(因为我现在又试了一次,但它不起作用 ARGGH)。但是下面的相同代码在过去也有效。

它在下面的文件系统对象功能上失败

Public Function GetFullFileName(strfilepath As String, _
strFileNamePartial As String) As String
Dim objFS As Variant
Dim objFolder As Variant
Dim objFile As Variant
Dim intLengthOfPartialName As Integer
Dim strfilenamefull As String
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strfilepath)
'work out how long the partial file name is
intLengthOfPartialName = Len(strFileNamePartial)

For Each objFile In objFolder.Files
    'Test to see if the file matches the partial file name
    If Left(LCase(Replace(objFile.Name, " ", "")), intLengthOfPartialName) = LCase(strFileNamePartial) Then
    'get the full file name
        strfilenamefull = objFile.Name
        Exit For
    Else
    End If
Next objFile

'Return the full file name as the function's value
GetFullFileName = strfilenamefull
End Function

当它到达 GetFolder(strfilepath) 代码时,我得到一个“运行时错误'76':找不到路径”

strfilepath 只是一个常规的共享点站点名称(例如,\teams.uk\gm\FX\SharedDocuments\London\11) November 2013\20 November\Reports)

如前所述,我尝试了文件路径的不同变体,包括 DavWWW,但似乎没有任何效果,我不知道还能尝试什么。

请问有什么建议吗?

谢谢

赖扬

4

1 回答 1

0

必须使用 FileSystemObject 启动 webclient 服务以访问 SharePoint。

当您第一次登录时,该服务通常不会启动。但是,当您通过普通用户界面访问 SharePoint 时,它就会启动。我认为这就是您的代码工作不一致的原因。

如果您在本地计算机上具有管理员权限,则可以手动(或使用代码)启动服务。但是,如果您没有权利,那么您可以尝试一个技巧 - 它很笨拙但有效。

使用 VBA 代码在资源管理器视图中打开一个已知的 SharePoint 文件夹,然后将其关闭。这将触发 webclient 启动。

于 2013-12-19T21:00:40.280 回答