我发现此链接https://sharepoint.stackexchange.com/questions/29021/import-sharepoint-list-into-excel-using-vba-only 人们已成功使用该链接自动将 SharePoint 2010 列表项导出到 Excel 2010 . 我可以用我的 SharePoint 数据获取 Excel 工作表。问题是我已经将 ID 作为我的 SharePoint 列表中的一个字段。vba代码自动生成ID(自动增量)并将其添加到excel文件中。现在我的 excel 中有两个 ID 字段名称。我想摆脱 excel vba 自动生成的 ID,并且只有我的 SharePoint 列表中的字段名称(ID 是其中之一)。我该怎么做?谢谢。
Sub TestMacro()
Dim objMyList As ListObject
Dim objWksheet As Worksheet
Dim strSPServer As String
Const SERVER As String = "http://abcd/"
Const LISTNAME As String = "{A486016E-80B2-44C3-8B4A-8394574B9430}"
Const VIEWNAME As String = ""
' 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 = Worksheets.Add
' 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),
True, , Range("a1"))
Set objMyList = Nothing
Set objWksheet = Nothing
End Sub