使用 VBA 打开 Sharepoint Excel 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12217680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Sharepoint Excel Files With VBA
提问by user1423997
I'm using VBA in Excel to loop through files on a sharepoint site and open all Excel files.
我在 Excel 中使用 VBA 来循环访问 sharepoint 站点上的文件并打开所有 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
回答by Shrout1
Instead of mapping the document library to a drive letter try using the WebDAV address to access the library in your code. This way if the macro is distributed no one will be dependent upon having the "Z:" drive being mapped to a specific location
不要将文档库映射到驱动器号,而是尝试使用 WebDAV 地址访问代码中的库。这样,如果宏被分发,没有人将依赖于将“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
\\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
\\sharepoint.site.com@SSL\DavWWWRoot\site1\usersite\Book2\Shared%20Documents
\Test_Text1.txt
Take a look at this blog postfor a full explanation on retrieving the WebDAV path.
查看此博客文章,了解有关检索 WebDAV 路径的完整说明。