vba VBA检查Sharepoint文件夹是否存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19693588/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:09:24  来源:igfitidea点击:

VBA Check If Sharepoint Folder Exists

excelvbasharepoint

提问by David L

I am trying to determine if a Sharepoint folder exists in Excel VBA using the URL path and if not create the folder. I can do this easily if I map the network drive:

我正在尝试使用 URL 路径确定 Excel VBA 中是否存在 Sharepoint 文件夹,如果不创建文件夹。如果我映射网络驱动器,我可以轻松地做到这一点:

 myWorkbookBasePath = "Z:Documents\Reports13\"

 If Dir(myWorkbookBasePath, vbDirectory) = "" Then
        MkDir myWorkbookBasePath
 End If

However, I can not figure out how to do it using the URL path. If I use

但是,我无法弄清楚如何使用 URL 路径来做到这一点。如果我使用

myWorkBookBasePath= "http://sharepoint/Documents/Reports/2013/"

I get error code 52. Can anyone tell me how to make it work with the URL path?

我收到错误代码 52。谁能告诉我如何使它与 URL 路径一起工作?

采纳答案by Adrian Sullivan

Give this a go

试一试

    myWorkBookBasePath= "\sharepoint\Documents\Reports13\"

or

或者

    myWorkBookBasePath = "http://sharepoint/Documents/Reports/2013/"
    myWorkBookBasePath = Replace(Replace(myWorkBookBasePath, "http:", ""), "/", "\")
    MsgBox (myWorkBookBasePath)

and in case of a Sharepoint site hosted using https

如果使用托管的 Sharepoint 站点 https

    myWorkBookBasePath = "https://sharepoint/Documents/Reports/2013/"
    myWorkBookBasePath = Replace(Replace(myWorkBookBasePath, "https:", ""), "/", "\")
    myWorkBookBasePath = Replace(myWorkBookBasePath, Split(myWorkBookBasePath, "\")(2), Split(myWorkBookBasePath, "\")(2) & "@SSL")
    MsgBox (myWorkBookBasePath)

MkDir in VBA can only access filesystem and does not understand URL's, so anything you can open in Explorer you can access with MkDir.

VBA 中的 MkDir 只能访问文件系统并且不理解 URL,因此您可以在资源管理器中打开的任何内容都可以使用 MkDir 访问。