Excel vba根据条件删除Excel中的重复列

时间:2012-04-13 19:06:12

标签: excel sharepoint-2010 excel-vba vba

我找到了此链接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

1 个答案:

答案 0 :(得分:0)

我正在做与您正在做的事情类似的事情,并添加了以下代码行:

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

.RefreshAll刷新表格的数据,当刷新表格时,它会删除该列。我目前仍在试图找出原因,但它确实解决了摆脱该专栏的问题。

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