2017-08-03 61 views
0

我試圖獲得一個adodb連接到SharePoint上的文件(我們有SharePoint 2013,據我所知)檢索並從我的本地驅動器上的另一個Excel文件上傳一些數據給它。 我可以做到這一點,當這兩個文件在我的本地驅動器與簡單的adodb連接,打開等。但我不明白如何做與DB文件被上傳到SP相同。ADODB連接到SharePoint上的Excel文件

我需要一些幫助來了解如何使其工作。

我知道我可以使用VBA從SP打開文件,但在這種情況下,我無法與它建立adodb連接。
謝謝

+0

https://sharepoint.stackexchange.com/help/on-topic可能會感興趣的。 – pnuts

+0

ADO無法通過HTTP工作 - 如果您有權訪問該文件,則可以使用WebDav路徑。 –

回答

0

我不完全確定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/