简体   繁体   English

从 EXCEL 到 SharePoint(SQL 数据库)的 ACCESS 文件连接

[英]ACCESS file connection from EXCEL to SharePoint (SQL database)

I have an access connection file (.accdb) that allows me to use EXCEL (Office 365) to query a SharePoint Library.我有一个访问连接文件 (.accdb),它允许我使用 EXCEL (Office 365) 查询 SharePoint 库。 It all works great EXCEPT for new files added to that SharePoint Library.除了添加到该 SharePoint 库的新文件外,这一切都很好。 I can query for and return all data for these new files/entries but cannot get the filename for these new entries for some reason.我可以查询并返回这些新文件/条目的所有数据,但由于某种原因无法获取这些新条目的文件名。 Any help would be most appreciated.非常感激任何的帮助。

Const SQLIMSSHAREPOINTCONNECTION = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\MORGAN\MACROS\IMS_SHAREPOINT_db.accdb"常量 SQLIMSSHAREPOINTCONNECTION = "Provider=Microsoft.ACE.OLEDB.12.0;数据源 = C:\MORGAN\MACROS\IMS_SHAREPOINT_db.accdb"

Sub routine:子程序:

Dim i As Long
Dim cn As Object
Dim rs As Object
Dim StrSql As String
Dim thePieces1() As String
Dim thePieces2() As String
Dim theFullFilename As String
Dim theShortFilename As String
       
StrSql = "SELECT [Name], [ID], [PartNumber(s)], [DateCompleted], [DocumentType], " & _
        "[WorkOrder(s)], [PurchaseOrder(s)], [SalesOrder(s)], [CustomerName(s)], [WorkCenter]" & _
        " FROM [Inspection Reports]"

Set cn = CreateObject("ADODB.Connection")
cn.Open SQLIMSSHAREPOINTCONNECTION
Set rs = CreateObject("ADODB.RECORDSET")
rs.ActiveConnection = cn
rs.Open StrSql
If Not (rs.BOF And rs.EOF) Then

    i = 1

    On Error Resume Next
    Do While Not rs.EOF

        i = i + 1
        theFullFilename = ""
        theShortFilename = ""
        ReDim thePieces1(10)

        thePieces1 = Split(rs.Fields(0), "#")
        theFullFilename = thePieces1(1)
        thePieces1() = Split(theFullFilename, "/")
        theShortFilename = thePieces1(UBound(thePieces1))

        Range("A" & i).Value = rs.Fields(1)      ' ID
        Range("B" & i).Value = theShortFilename  ' Filename
        Range("C" & i).Value = rs.Fields(2)      ' PartNumber(s)
        Range("D" & i).Value = rs.Fields(3)      ' DateCompleted
        Range("E" & i).Value = rs.Fields(4)      ' DocumentType
        Range("F" & i).Value = rs.Fields(5)      ' WorkOrder(s)
        Range("G" & i).Value = rs.Fields(6)      ' PurchaseOrder(s)
        Range("H" & i).Value = rs.Fields(7)      ' CustomerName
        Range("I" & i).Value = rs.Fields(8)      ' WorkCenter

        rs.MoveNext
        
    Loop

我不清楚您的共享点访问 Excel 连接是如何工作的,但您的记录集 (rs) 在更新共享点数据后可能需要刷新或重新查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM