Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Add Method
Collapse the table of content
Expand the table of content

ListObjects.Add Method

Office 2007
Creates a new list object.

Syntax

expression.Add(SourceType, Source, LinkSource, HasHeaders, Destination)

expression   A variable that represents a ListObjects object.

Parameters

NameRequired/OptionalData TypeDescription
SourceTypeOptionalXlListObjectSourceTypeIndicates the kind of source for the query.
SourceOptionalVariantwhen SourceType = xlSrcRange. A Range object representing the data source. If omitted, the Source will default to the range returned by list range detection code. when SourceType = xlSrcExternal. An array of String values specifying a connection to the source, containing the following elements:
  • 0 - URL to SharePoint site
  • 1 - ListName
  • 2 - ViewGUID
LinkSourceOptionalVariantBoolean. 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.
TableStyleNameOptionalVariantAn XlYesNoGuess constant that indicates whether the data being imported has column labels. If the Source does not contain headers, Excel will automatically generate headers.
DestinationOptionalVariantA 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 ListObjects collection specified by expression. New columns will be inserted at the Destination to fit the new list. Therefore, existing data will not be overwritten.

Return Value
A ListObject object that represents the new list object.

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.

Example

The following example adds a new ListObject object based on data from a Microsoft Windows SharePoint Services site to the default ListObjects collection and places the list in cell A1 in the first worksheet of the workbook.

Bb211863.vs_note(en-us,office.12).gif  Note
The following code example assumes that you will substitute a valid server name and the list guid in the variables strServerName and strListGUID. Additionally, the server name must be followed by "/_vti_bin" or the sample will not work.
Visual Basic for Applications
Set objListObject = ActiveWorkbook.Worksheets(1).ListObjects.Add(SourceType:= xlSrcExternal, _
	Source:= Array(strServerName, strListName, strListGUID), LinkSource:=True, _
	TableStyleName:=xlGuess, Destination:=Range("A10"))



Community Additions

ADD
Show:
© 2015 Microsoft