【问题标题】:How to open a file in a Sharepoint site using VBA如何使用 VBA 在 Sharepoint 站点中打开文件
【发布时间】:2015-07-16 23:38:21
【问题描述】:

我正在尝试打开一个文件名每周都会更改的文件。这意味着文件名上的日期部分是不同的。此外,此文件是文件夹内的唯一文件。但它的文件名正在改变。我正在使用下面的代码,但它抛出了错误,“运行时间 52:错误的文件名和编号”。我需要你的帮助。

 Dim ThePath As String
 Dim TheFile As String

        ThePath = "https://ts.company.com/sites/folder1/folder2/folder3/folder4/"
        TheFile = Dir(ThePath & "MANILA_ShiftRecord_*" & ".xlsx")
        Workbooks.Open (ThePath & TheFile)

谢谢!

【问题讨论】:

标签: vba excel sharepoint sharepoint-2010


【解决方案1】:

如果只有一个文件,您可以使用这种方法:

Dim sharepointFolder As String
Dim colDisks As Variant
Dim objWMIService As Object
Dim objDisk As Variant
Dim driveLetter As String

'Create FSO and network object
Set objNet = CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")

'Get all used Drive-Letters
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

'Loop through used Drive-Letters
For Each objDisk In colDisks
    For i = 65 To 90
        'If letter is in use exit loop and remember letter.
        If i = Asc(objDisk.DeviceID) Then
            j = i
            Exit For
        'letters which are not checked yet are possible only
        ElseIf i > j Then
            driveLetter = Chr(i) & ":"
            Exit For
        End If
    Next i
    'If a Drive-Letter is found exit the loop
    If driveLetter <> "" Then
        Exit For
    End If
Next

'define path to SharePoint
sharepointFolder = "https://spFolder/Sector Reports/"
'Map the sharePoint folder to the free Drive-Letter
objNet.MapNetworkDrive driveLetter, sharepointFolder
'set the folder to the mapped SharePoint-Path
Set folder = fs.GetFolder(driveLetter)

之后,您可以使用文件系统对象函数处理文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多