我不太确定 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/