ADODB连接到SharePoint上的Excel文件

时间:2017-08-03 19:54:34

标签: excel vba excel-vba sharepoint adodb

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

我需要一些帮助来了解如何使其发挥作用。

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

1 个答案:

答案 0 :(得分:0)

我不完全确定ADODB和SharePoint。你可以让它工作,但它可能比它的价值更麻烦。你当然可以CheckIn和CheckOut文件!!

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/

相关问题