如果文件存在于sharepoint站点上,是否可以通过VBA进行检查? [英] Is it possible to check via VBA if file exist on a sharepoint site?

查看:383
本文介绍了如果文件存在于sharepoint站点上,是否可以通过VBA进行检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Excel(2010)宏,它在某种程度上必须确认企业sharepoint站点上存在某个文件(doc / pdf)。
该文件可通过Internet Explorer访问(所有权限授予用户)。
我有一个直接链接到该文件。
我不需要打开它,只需检查是否存在。

I'm trying to write an Excel (2010) macro that at some point would have to confirm existence of a certain file (doc/pdf) on a corporate sharepoint site. The file is accessible through Internet Explorer (all rights are granted to the user). I have a direct link to that file. I don't need to open it, just check if it's there.

如果这是一个本地文件,我将使用Dir()来检查如果文件存在。
但是,这不符合URI。

If this was a local file, I'd use Dir() to check if the file exists. However, this won't work with URIs.

我通过objHttp尝试了一种基于GET的方法,但是我接收到的唯一响应是一个渗透,表示我没有权限查看此页面[in tag]。

I tried a method based on GET via objHttp but the only response I recieve is a wepage stating that "I am not authorized to view this page" [in tag].

这是否可以以任何方式进行?

Is this doable in any way?

推荐答案

给这个镜头:

Function checkFile(URLStr As String) As Boolean
    Dim oHttpRequest As Object
    Set oHttpRequest = New MSXML2.XMLHTTP60
    With oHttpRequest
        .Open "GET", URLStr, False, [Username], [Password]
        .setRequestHeader "Cache-Control", "no-cache"
        .setRequestHeader "Pragma", "no-cache"
        .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
        .send
    End With
    If oHttpRequest.Status = 200 Then
        checkFile = True
    Else
        checkFile = False
    End If
End Function

URLStr 应该是http://sharepoint/site/user.xlsx。在 .Open 行中输入您的用户名/密码,以将其传递到网站,这对于任何URI(我以.xlsx文件为例进行测试)都适用。我应该指出,在我的内部SharePoint网站上,我不需要通过UN / PW来运行这个功能,所以如果这样做是最终的,只需从。打开呼叫。此外,所有的标题可能不是必需的,但是我总是在我的请求中使用它们,所以我把它们留下。

URLStr should be something like "http://sharepoint/site/user.xlsx". Enter your Username/Password in the .Open line to pass them to the site, and this should work for any URI (I was testing it against .xlsx files for example). I should point out that on my internal SharePoint sites, I don't need to pass the UN/PW in order to run this function, so if that ends up being the case for you, just remove those parameters from the .Open call. Also, all the header stuff probably isn't necessary, but I always have them in my requests so I left them in.

这篇关于如果文件存在于sharepoint站点上,是否可以通过VBA进行检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆