Share via


Lists Collection

SharePoint Designer Developer Reference

Represents the collection of all List objects in the current Web site.

Remarks

Lists allow information to be shared and exchanged between different users and different Web sites.

Use the Lists property of the Web object to return the collection of all lists in the Web site. Use Lists(Index), where Index is either the name of the list or its numeric position within the collection, to return a single List object.

The following example displays the names of all lists in the active Web site. If the active Web site does not contain any lists, a message is displayed to the user.

Visual Basic for Applications
Sub ListAllLists()
'Displays the names of all lists in the collection
    Dim lstWebList As List
    Dim strName As String
    'Check if any lists exist
    If Not ActiveWeb.Lists Is Nothing Then
        'Cycle through lists
        For Each lstWebList In ActiveWeb.Lists
            'add list names to string
            If strName = "" Then
                strName = lstWebList.Name & vbCr
            Else
                strName = strName & lstWebList.Name & vbCr
            End If
        Next
        'Display names of all lists
        MsgBox "The names of all lists in the current Web site are:" _
               & vbCr & strName
    Else
        'Other wise display message to user
        MsgBox "The current Web site contains no lists."
    End If
End Sub

Use the Lists.Add method to add a new list to the Lists collection. The following example adds a new list of type fpBasicList named NewShare to the active Web site.

Visual Basic for Applications
Sub NewList()
'Adds a new list to the current Web site
    Dim objApp As Application
    Dim objLists As Lists
    Set objApp = Application
    Set objLists = objApp.ActiveWeb.Lists
    'Add new list
    objLists.Add Name:="NewShare", _
                 ListType:=fpListTypeBasicList, _
                 Description:="List of Shared files"
    'Display message to user
    MsgBox "A new list was added to the Lists collection."
End Sub

See Also