Run time error '1004': Cannot connect to the server at this time. Changes to your data cannot be saved
I'm learning to export the Sharepoint list to the excel by VBA. I found some code as an example from the internet, and I was trying to get started from there. But when I ran the code, the error "Run time error '1004': Cannot connect to the server at this time. Changes to your data cannot be saved" appears. I did some research in the internet, but it seems there're not a lot of answers. Does anybody have an idea about this issue? Thanks!
Code:
Sub ImportSharePointList()
Dim objMyList As ListObject
Dim objWksheet As Worksheet
Dim strSPServer As String
Const SERVER As String = "collaboration.xxx.com/content/00001433/Sites/Lists/Travel%20Tracker%20Alt/AllItems.aspx"
Const LISTNAME As String = "{CD832B54-0D28-4EF2-9DB3-557262356D4C}"
Const VIEWNAME As String = "{A6599E87-5CA1-403B-AED9-1F60F539A09B}"
' The SharePoint server URL pointing to
' the SharePoint list to import into Excel.
strSPServer = "http://" & SERVER & "/_vti_bin"
' Add a new worksheet to the active workbook.
Set objWksheet = ActiveWorkbook.Sheets("Data")
' Add a list range to the newly created worksheet
' and populated it with the data from the SharePoint list.
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
Array(strSPServer, LISTNAME, VIEWNAME), False, , Range("A2"))
End Sub