AddCustomList 方法 (Excel)Application.AddCustomList method (Excel)

为自定义自动填充和/或自定义排序添加自定义列表。Adds a custom list for custom autofill and/or custom sort.

语法Syntax

表达式AddCustomList(ListArray, ByRow)expression.AddCustomList (ListArray, ByRow)

expression:表示 Application 对象的变量。expression A variable that represents an Application object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
ListArrayListArray 必需Required VariantVariant 将源数据指定为字符串数组或 Range 对象。Specifies the source data, as either an array of strings or a Range object.
ByRowByRow 可选Optional VariantVariant 仅当_ListArray_为Range对象时才使用。Only used if ListArray is a Range object. 如果为 True, 则从区域中的每行创建自定义列表。True to create a custom list from each row in the range. 如果为 False , 则从区域中的每个列创建自定义列表。False to create a custom list from each column in the range.

如果省略此参数, 并且行数多于列 (或行数和列数) 的范围中, 则 Microsoft Excel 将根据区域中的每个列创建一个自定义列表。If this argument is omitted and there are more rows than columns (or an equal number of rows and columns) in the range, Microsoft Excel creates a custom list from each column in the range.

如果省略此参数, 并且列数多于范围中的行数, 则 Excel 将根据区域中的每一行创建一个自定义列表。If this argument is omitted and there are more columns than rows in the range, Excel creates a custom list from each row in the range.

说明Remarks

如果您尝试添加的列表已经存在, 则此方法将引发运行时错误1004。If the list that you are trying to add already exists, this method throws a run-time error 1004. 使用On error语句捕获错误。Catch the error with an On Error statement.

示例Example

本示例将一个字符串数组添加到自定义列表中。This example adds an array of strings as a custom list.

On Error Resume Next  ' if the list already exists, do nothing
Application.AddCustomList Array("cogs", "sprockets", _ 
 "widgets", "gizmos")
On Error Goto 0       ' resume regular error handling

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.