我在Excel中使用VBA循环浏览共享点网站上的文件并打开所有Excel文件。
当我第一次运行Excel时,代码会崩溃,但是,如果我重新打开它,它会正常工作。
这方面有什么已知的问题吗?
谢谢。
编辑:这是代码:
Sub Refresh()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Dim fso As FileSystemObject
Dim fldr As Folder
Dim f As File
Dim wb As Workbook
Set fso = New FileSystemObject
Set fldr = fso.GetFolder(SharePointSite)
For Each f In fldr.Files
Set wb = Workbooks.Open(SharePointURL & f.Name)
Next f
Set wb = Nothing
Set fldr = Nothing
Set fso = Nothing
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
不要将文档库映射到驱动器号,而是尝试使用WebDAV地址访问代码中的库。这样,如果宏是分布式的,没有人会依赖于将"Z:"驱动器映射到特定位置的
将FilePath变量设置为如下字符串(HTTPS站点使用@SSL):
\sharepoint.site.com@SSLDavWWWRootsite1usersiteBook2Shared%20Documents
如果你要直接访问文本文件,那么设置如下:
\sharepoint.site.com@SSLDavWWWRootsite1usersiteBook2Shared%20Documents
Test_Text1.txt
看看这篇博客文章,了解有关检索WebDAV路径的完整解释。