【问题标题】:ADODB connection to an Excel file on SharePointADODB 连接到 SharePoint 上的 Excel 文件
【发布时间】:2017-08-08 11:28:08
【问题描述】:

我正在尝试与 SharePoint 上的文件建立 adodb 连接(据我所知,我们有 sharepoint 2013),以从本地驱动器上的另一个 excel 文件中检索和上传一些数据。 当这两个文件在我的本地驱动器上时,我可以通过简单的 adodb 连接、打开等操作。但我不明白如何将数据库文件上传到 SP。

我需要一些帮助来了解如何使它工作。

我知道我可以使用 VBA 从 SP 打开文件,但在这种情况下,我无法与它建立 adodb 连接。
谢谢

【问题讨论】:

  • ADO 不能通过 HTTP 工作 - 如果您有权访问该路径,则可以使用 WebDav 路径。

标签: vba excel sharepoint adodb


【解决方案1】:

我不太确定 ADODB 和 SharePoint。你可能会得到它的工作,但它可能比它的价值更麻烦。你当然可以签入和签出文件!!

Sub CheckOut()
    Dim docCheckOut As String
    'docCheckOut = "//office.bt.com/sites/Training/Design Admin/Training Plan/adamsmacro.xlsm"
    docCheckOut = "http://excel-pc:/ExcelList.xlsb"
    Call UseCheckOut(docCheckOut)
End Sub

Sub UseCheckOut(docCheckOut As String)
     ' Determine if workbook can be checked out.
    If Workbooks.CanCheckOut(docCheckOut) = True Then
        Workbooks.CheckOut docCheckOut
    Else
        MsgBox "Unable to check out this document at this time."
    End If
End Sub

您也可以轻松打开和关闭工作簿。

Sub OpenAndCloseWBFromSharePointFolder()

'If nobody has the file checked out
If Workbooks.CanCheckOut("http://excel-pc/ExcelList.xlsb") = True Then
Application.DisplayAlerts = False

'Open the file on the SharePoint server
Workbooks.Open Filename:="http://excel-pc/ExcelList.xlsb", UpdateLinks:=xlUpdateLinksNever

'Close the workbook
Workbooks("ExcelList.xlsb").Close
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False

'Open the File to check if you already have it checked out
Workbooks.Open Filename:="http://excel-pc/ExcelList.xlsb", UpdateLinks:=xlUpdateLinksNever

'See if doc can be checked in
If Application.Workbooks("ExcelList.xlsb").CanCheckIn Then

'Check In, Save and Close
Application.Workbooks("ExcelList.xlsb").CheckIn SaveChanges:=True, Comments:="Checked-In before Delete"

'Open the file again
Workbooks.Open Filename:="http://excel-pc//ExcelList.xlsb"

'Close the workbook
Workbooks("ExcelList.xlsb").Close
End If
End If

End Sub

您甚至可以更新特定单元格中的值!

Sub UpdateSpecificCells()

'If nobody has the file checked out
If Workbooks.CanCheckOut("http://excel-pc//ExcelList.xlsb") = True Then
Application.DisplayAlerts = False

'Open the file on the SharePoint server
Workbooks.Open Filename:="http://excel-pc//ExcelList.xlsb", UpdateLinks:=xlUpdateLinksNever


ActiveSheet.Cells(2, 7).Value = 100
ActiveSheet.Cells(3, 7).Value = 200
ActiveSheet.Cells(4, 7).Value = 300


'Close the workbook
Workbooks("ExcelList.xlsb").Save
Workbooks("ExcelList.xlsb").Close

End If
End Sub

您甚至可以使用 VBA 创建文件夹并使用 VBA 列出文件和文件夹。我很想知道是否有人用 ADODB 解决方案在这里发帖!与此同时,这可能值得一看。

https://scottlyerly.wordpress.com/2014/05/14/excel-geeking-using-vba-and-ado-to-pull-data-from-sharepoint-lists/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-10
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    相关资源
    最近更新 更多