title: How to import SharePoint List into Excel VBA?
body: <p>Using the following code to import data from SharePoint using Excel VBA, the following error comes up:</p>
  
  <blockquote>
    <p>Run-time error '1004':<br>
     An unexpected error has occurred. Changes to your data cannot be saved</p>
  </blockquote>
  
  <pre><code>Sub ImportSharePointList()
  
      Dim objMyList As ListObject
      Dim objWksheet As Worksheet
      Dim strSPServer As String
  
  
      Const SERVER As String = "&lt;server&gt;:&lt;Port&gt;/Location/Lists"
      Const LISTNAME As String = "{4e78c371-9ff0-410d-86a5-b78499091369}"
      Const VIEWNAME As String = "{C3BD0F82-6BCD-45EF-B43E-DCFEA78067B0}"
  
      strSPServer = "http://" &amp; SERVER &amp; "/_vti_bin"
  
      Set objWksheet = Worksheets.Add
  
      Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
          Array(strSPServer, LISTNAME, VIEWNAME), False, xlYes, Range("A1"))
  
  End Sub
  </code></pre>