ListObjects.Add Method
Creates a new list object. Returns a ListObject object.
Namespace: Microsoft.Office.Interop.Excel
Assembly: Microsoft.Office.Interop.Excel (in Microsoft.Office.Interop.Excel.dll)
Syntax
'Declaration
Function Add ( _
SourceType As XlListObjectSourceType, _
Source As Object, _
LinkSource As Object, _
XlListObjectHasHeaders As XlYesNoGuess, _
Destination As Object _
) As ListObject
'Usage
Dim instance As ListObjects
Dim SourceType As XlListObjectSourceType
Dim Source As Object
Dim LinkSource As Object
Dim XlListObjectHasHeaders As XlYesNoGuess
Dim Destination As Object
Dim returnValue As ListObject
returnValue = instance.Add(SourceType, _
Source, LinkSource, XlListObjectHasHeaders, _
Destination)
ListObject Add(
XlListObjectSourceType SourceType,
Object Source,
Object LinkSource,
XlYesNoGuess XlListObjectHasHeaders,
Object Destination
)
Parameters
SourceType
Type: Microsoft.Office.Interop.Excel.XlListObjectSourceTypeOptional 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
Type: System.ObjectOptional 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#
Contents
0
URL to SharePoint site
1
ListName
2
ViewGUID
LinkSource
Type: System.ObjectOptional 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
Type: Microsoft.Office.Interop.Excel.XlYesNoGuessOptional 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
Type: System.ObjectOptional 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.
Return Value
Type: Microsoft.Office.Interop.Excel.ListObject
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.