Excel vba根据标准删除Excel中的重复列

我发现这个链接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 

我正在做类似于你正在做的事情,我添加了以下几行代码:

 Application.DisplayAlerts = False ActiveWorkbook.Save ActiveWorkbook.RefreshAll ActiveWorkbook.Save Application.DisplayAlerts = True 

.RefreshAll刷新表的数据,刷新时删除该列。 我现在仍然在试图弄清楚为什么,但它确实解决了摆脱这一问题的问题。

编辑:我知道这是回答3年前的一个问题,但认为这可能会帮助那些偶然发现这个问题的人。