I need some help with the code to query and retrieve the data from the excel file saved on the Sharepoint server.
The Code works fine here when i use local path
Sub ConnectToSharePointExcel()
' Set your SharePoint path to the Excel file
Dim sharePointPath As String
Dim conn As ADODB.Connection
Dim result1 As Object
Set conn = CreateObject("ADODB.Connection")
sharePointPath = "C:\Users\" & Environ("username") & "\orgname\Base Tables\Master Data.xlsx"
' Create a connection string
conn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & sharePointPath & _
";Extended Properties=""Excel 12.0;HDR=Yes;"";"
conn.Open
' Open the connection
conn.Open connString
sqlQuery = "SELECT * FROM [Master_Ocean_New$]"
Set result1 = conn.Execute(sqlQuery)
' Process the data or do something with the recordset
' Close the connection
conn.Close
End Sub
But following gives an error when i tried with sharepoint path. Able to establish a connection but unable to query.
Sub ConnectToSharePointExcel()
' Set your SharePoint path to the Excel file
Dim sharePointPath As String
Dim conn As ADODB.Connection
Dim result1 As Object
Set conn = CreateObject("ADODB.Connection")
sharePointPath = "\\sharepoint\sites\orgname\Shared%20Documents\Base%20Tables\Master%20Data.xlsx"
' Create a connection string
Dim connString As String
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"WSS;HDR=YES;IMEX=2;" & _
"RetrieveIds=Yes;" & _
"DATABASE=" & sharePointPath & ";"
conn.open
Dim sqlQuery As String
sqlQuery = "SELECT * FROM [Master_Ocean_New$]"
Set result1 = conn.Execute(sqlQuery)
' Process the data or do something with the recordset
' Close the connection
conn.Close
End Sub
Getting Error at line "Set result1 = conn.Execuute(sqlQuery)"