[英]Open Sharepoint Excel Files With VBA
I'm using VBA in Excel to loop through files on a sharepoint site and open all Excel files. 我在Excel中使用VBA在共享点网站上循环浏览文件并打开所有Excel文件。
The code crashes Excel the first time I run it, however, if I then reopen it it works fine. 我第一次运行它时,代码使Excel崩溃,但是,如果我重新打开它,它将运行正常。
Are there any known issues around this? 周围是否有任何已知问题?
Thanks. 谢谢。
Edit: Here is the code: 编辑:这是代码:
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
Instead of mapping the document library to a drive letter try using the WebDAV address to access the library in your code. 不要将文档库映射到驱动器号,而是尝试使用WebDAV地址访问代码中的库。 This way if the macro is distributed no one will be dependent upon having the "Z:" drive being mapped to a specific location
这样,如果分发了宏,则不会有人依赖于将“ Z:”驱动器映射到特定位置
Set your FilePath variable equal to a string like this (use @SSL for HTTPS sites): 将FilePath变量设置为等于这样的字符串(对于HTTPS站点,请使用@SSL):
\\\\sharepoint.site.com@SSL\\DavWWWRoot\\site1\\usersite\\Book2\\Shared%20Documents
If you are going to access the text file directly then set it up like this: 如果您要直接访问文本文件,请按以下步骤进行设置:
\\\\sharepoint.site.com@SSL\\DavWWWRoot\\site1\\usersite\\Book2\\Shared%20Documents \\Test_Text1.txt
Take a look at this blog post for a full explanation on retrieving the WebDAV path. 请参阅此博客文章 ,以获取有关检索WebDAV路径的完整说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.