I am trying to import a list from SharePoint to Excel via VBA. I do know the Server name for certain, but I am not sure how to find out the LISTNAME and VIEWNAME variables, also I would like to automatically log in to SharePoint with default (Windows) credentials, how could I insert that into my code?
Here is my code (for security reasons I had to clear some entries with XXXX) I'd appreciate the help:
Sub ImportSPList()
Dim objMyList As ListObject
Dim objWksheet As Worksheet
Dim strSPServer As String
Const SERVER As String = "https://xxxxxx.xxx.xxxx.net/sites/RiskMgmt/xxxAudit"
Const LISTNAME As String = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"
Const VIEWNAME As String = "ALL Datasheet View"
strSPServer = SERVER
Set objWksheet = Worksheets.Add
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
Array(strSPServer, LISTNAME, VIEWNAME), False, , Range("A1"))
End Sub
"ADODB.Connection"and"ADODB.Recordset"to connect to the list in SharePoint, and then read the values (or update them) from Excel.