Accessing Sharepoint List from Excel/VBA using ADODB connection

Scotster

Board Regular
Joined
May 29, 2017
Messages
54
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi there,

I'm migrating an entire suite of excel files that currently access a database in order to see if a person is allowed access. I use an ADODB connection and it works great. I'm hoping that I can use the "Lists" feature in Sharepoint to copy this access solution but I'm really struggling with finding out the correct syntax.

What I have now is as follows:
Code:
Dim cnt As ADODB.Connection
    Dim mySQL As String
    Dim strSharepointListID As String, strSharepointSite As String
   

    strSharepointListID = "{Removed}"
    strSharepointSite = "[https://Website.com/sites/Project/]"
   
    Set cnt = New ADODB.Connection
    With cnt
        .ConnectionString = _
        "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=" & strSharepointSite '& ";LIST=FileAccess;"
        .Open
    End With
   
Set rs = New ADODB.Recordset

i = 2
With rs
    .ActiveConnection = cnt
    .Open "SELECT * FROM TABLE"
     For i = 1 To .Fields.Count
         Debug.Print .Fields(i - 1).Name
         Debug.Print .Fields(i - 1).Type
     Next i
End With

The main things I'm unsure of are the Sharepoint site, the "LIST" and with those combined, how to select the "Table" for the record set.

For the site, the full link (redacted) to the table is as follows:
I have the correct list ID which I got from Sharepoint settings {xxxx-xxxx-xxxx-xxxx} etc.

Typically for the connection I would want to select the "Database" name, in this case I'm not sure what it's called. Is it called Lists? FileAccess (from what I understand) is the Table name.

To summarise:

strSharepointSite = "[https://website.com/sites/Project/]" - I'm unsure what this should be given the link above?
LIST=FileAccess - I really want this to be the DB but unsure how to reference/
.Open "SELECT * FROM TABLE" - I really want this to be the FileAccess table but need the correct List first.

Any help would be greatly appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I believe that the List and table name are the same.
 
Upvote 0
I believe that the List and table name are the same.
I had all but given up but I saw this reply and I kept plodding along. Firstly, you are absolutely spot on, they are both the same. Secondly, for anyone looking to do something similar, the key is to avoid any brackets or anything in the setup. Solution as follows:

Code:
Dim cnt As ADODB.Connection
    Dim mySQL As String
    Dim strSharepointListID As String, strSharepointSite As String
   

    strSharepointListID = "2AB5e630-b635f-4FG6-b6e9-10432ca3712g" 'Changed for posting
    strSharepointSite = "https://Website.com/sites/Project/"
   
    Set cnt = New ADODB.Connection
    With cnt
        .ConnectionString = _
        "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=" & strSharepointSite '& ";LIST=" & strSharepointListID & ";"
        .Open
    End With
   
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM [" & strSharepointListID & "]", cnt
debug.print rs.Fields.Count

Hopefully of use to someone :)
 
Upvote 0
Solution
Thanks for posting back - I'm sure someone will find it helpful. :)
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top