ListObjects.Add Method

Definition

Creates a new list object. Returns a ListObject object.

public Microsoft.Office.Interop.Excel.ListObject Add (Microsoft.Office.Interop.Excel.XlListObjectSourceType SourceType = Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, object Source, object LinkSource, Microsoft.Office.Interop.Excel.XlYesNoGuess XlListObjectHasHeaders = Microsoft.Office.Interop.Excel.XlYesNoGuess.xlGuess, object Destination);
Public Function Add (Optional SourceType As XlListObjectSourceType = Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, Optional Source As Object, Optional LinkSource As Object, Optional XlListObjectHasHeaders As XlYesNoGuess = Microsoft.Office.Interop.Excel.XlYesNoGuess.xlGuess, Optional Destination As Object) As ListObject

Parameters

SourceType
XlListObjectSourceType

Optional XlListObjectSourceType. Indicates the kind of source for the query. Can be one of the following XlListObjectSourceType constants: xlSrcExternal or xlSrcRange. If omitted, the SourceType will default to xlSrcRange.

Source
Object

Optional when SourceType is xlSrcRange. A Range object representing the data source. If omitted, the Source will default to the range returned by list range detection code. Required when SourceType is xlSrcExternal. An array of String values specifying a connection to the source.Element#Contents0URL to SharePoint site 1ListName 2ViewGUID

LinkSource
Object

Optional Boolean. Indicates whether an external data source is to be linked to the ListObject object. If SourceType is xlSrcExternal, default is True. Invalid if SourceType is xlSrcRange, and will return an error if not omitted.

XlListObjectHasHeaders
XlYesNoGuess

Optional Object. An XlYesNoGuess constant that indicates whether the data being imported has column labels. If the Source does not contain headers, Excel will automatically generate headers.

Destination
Object

Optional Object. A Range object specifying a single-cell reference as the destination for the top-left corner of the new list object. If the Range object refers to more than one cell, an error is generated. The Destination argument must be specified when SourceType is set to xlSrcExternal. The Destination argument is ignored if SourceType is set to xlSrcRange. The destination range must be on the worksheet that contains the specified ListObjects collection. New columns will be inserted at the Destination to fit the new list. Therefore, existing data will not be overwritten.

Returns

Remarks

When the list has headers, the first row of cells will be converted to Text, if not already set to text. The conversion will be based on the visible text for the cell. This means that if there is a date value with a Date format that changes with locale, the conversion to a list might produce different results depending on the current system locale. Moreover, if there are two cells in the header row that have the same visible text, an incremental Integer will be appended to make each column header unique.

Applies to