Add Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Add method as it applies to the NewFile object.

Adds a new item to the NewItem task pane. Returns a Boolean. True if the item was successfully added.

expression.Add(FileName, Section, DisplayName, Action)

expression Required. An expression that returns one of the above objects.

FileName Required String. The name of the file to add to the list of files on the task pane.

Section Optional Variant. The section to which to add the file. Can be any msoFileNewSection constant.

DisplayName Optional Variant. The text to display in the task pane.

Action Optional Variant. The action to take when a user clicks on the item. Can be any msoFileNewAction constant.

Add method as it applies to the CommandBars object.

Creates a new command bar and adds it to the collection of command bars. Returns a CommandBar object.

expression.Add(Name, Position, MenuBar, Temporary)

expression Required. An expression that returns a CommandBars object.

Name Optional Variant. The name of the new command bar. If this argument is omitted, a default name is assigned to the command bar (such as Custom 1).

Position Optional Variant. The position or type of the new command bar. Can be one of the MsoBarPosition constants listed in the following table.

Constant Description
msoBarLeft, msoBarTop, msoBarRight, msoBarBottom Indicates the left, top, right, and bottom coordinates of the new command bar
msoBarFloating Indicates that the new command bar won't be docked
msoBarPopup Indicates that the new command bar will be a shortcut menu
msoBarMenuBar Macintosh only

MenuBar Optional Variant. True to replace the active menu bar with the new command bar. The default value is False.

Temporary Optional Variant. True to make the new command bar temporary. Temporary command bars are deleted when the container application is closed. The default value is False.

Add method as it applies to the CommandBarControls object.

Creates a new CommandBarControl object and adds it to the collection of controls on the specified command bar.

expression.Add(Type, Id, Parameter, Before, Temporary)

expression Required. An expression that returns a CommandBarControls object.

Type Optional Variant. The type of control to be added to the specified command bar. Can be one of the following MsoControlType constants: msoControlButton, msoControlEdit, msoControlDropdown, msoControlComboBox, or msoControlPopup.

Id Optional Variant. An integer that specifies a built-in control. If the value of this argument is 1, or if this argument is omitted, a blank custom control of the specified type will be added to the command bar.

Parameter Optional Variant. For built-in controls, this argument is used by the container application to run the command. For custom controls, you can use this argument to send information to Visual Basic procedures, or you can use it to store information about the control (similar to a second Tag property value).

Before Optional Variant. A number that indicates the position of the new control on the command bar. The new control will be inserted before the control at this position. If this argument is omitted, the control is added at the end of the specified command bar.

Temporary Optional Variant. True to make the new control temporary. Temporary controls are automatically deleted when the container application is closed. The default value is False.

Add method as it applies to the DocumentProperties object.

Creates a new custom document property. You can only add a new document property to the custom DocumentProperties collection.

expression.Add(Name, LinkToContent, Type, Value, LinkSource)

expression Required. The custom DocumentProperties object.

Name Required String. The name of the property.

LinkToContent Required Boolean. Specifies whether the property is linked to the contents of the container document. If this argument is True, the LinkSource argument is required; if it's False, the value argument is required.

Type Optional Variant. The data type of the property. Can be one of the following MsoDocProperties constants: msoPropertyTypeBoolean, msoPropertyTypeDate, msoPropertyTypeFloat, msoPropertyTypeNumber, or msoPropertyTypeString.

Value Optional Variant. The value of the property, if it's not linked to the contents of the container document. The value is converted to match the data type specified by the type argument, if it can't be converted, an error occurs. If LinkToContent is True, the Value argument is ignored and the new document property is assigned a default value until the linked property values are updated by the container application (usually when the document is saved).

LinkSource Optional Variant. Ignored if LinkToContent is False. The source of the linked property. The container application determines what types of source linking you can use.

Remarks

If you add a custom document property to the DocumentProperties collection that’s linked to a given value in a Microsoft Office document, you must save the document to see the change to the DocumentProperty object.

Add method as it applies to the FileDialogFilters object.

Adds a new file filter to the list of filters in the Files of type drop down list box in the File dialog box. Returns a FileDialogFilter object that represents the newly added file filter.

expression.Add(Description, Extensions, Position)

expression Required. An expression that returns one of the above objects.

Description Required String. The text representing the description of the file extension you want to add to the list of filters.

Extensions Required String. The text representing the file extension you want to add to the list of filters. More than one extension may be specified and each must be separated by a semi-colon (;). For example, the Extensions argument can be assigned to the string: "*.txt; *.htm". Note Parentheses do not need to be added around the extensions. Office will automatically add parentheses around the extensions string when the description and extensions strings are concatenated into one file filter item.

Position Optional Variant. A number that indicates the position of the new control in the filter list. The new filter will be inserted before the filter at this position. If this argument is omitted, the filter is added at the end of the list.

Remarks

Each filter in a list is made up of two parts: the file extension (e.g. .txt) and the text description of the file extension (e.g. Text Files). Together, the file filter would appear in the Files of type drop down list box as: Text Files (*.txt).

Note that when a filter is added to the list, the default filters are not removed.

Filters are only displayed when the Windows option is checked.

If Position is invalid, an out of range runtime error is displayed. If the Description and Extensions value are invalid, a runtime error (parse) is displayed.

Folder picker dialogs do not have filters, therefore, filter methods do not apply to the folder picker.

Add method as it applies to the Scripts object.

Adds a Script object to the Scripts collection of one of the following objects: a Document or Range object in Microsoft Word; a Worksheet or Chart object in Microsoft Excel; or a Slide, SlideRange, slide Master, or title Master object in Microsoft PowerPoint. Returns a Script object.

expression.Add(Anchor, Location, Language, Id, Extended, ScriptText)

expression Required. The Scripts collection.

Anchor Optional Range (Microsoft Excel only). The Anchor argument accepts an Excel Range object, which specifies the placement of the script anchor on an Excel Worksheet. You cannot insert script anchors into Excel charts.

MsoScriptLocation

MsoScriptLocation can be one of these MsoScriptLocation constants.
msoScriptLocationInBodydefault
msoScriptLocationInHead

MsoScriptLanguage

MsoScriptLanguage can be one of these MsoScriptLanguage constants.
msoScriptLanguageASP
msoScriptLanguageJava
msoScriptLanguageOther
msoScriptLanguageVisualBasicdefault

Id Optional String. The ID of the <SCRIPT> tag in HTML. The Id argument specifies an SGML identifier used for naming elements. Valid identifiers include any string that begins with a letter and is composed of alphanumeric characters; the string can also include the underscore character ( _ ). The ID must be unique within the HTML document. This parameter is exported as the ID attribute in the <SCRIPT> tag.

Extended Optional String. Specifies attributes that are to be added to the <SCRIPT> tag (LANGUAGE and ID attributes are exported through the Language and Id parameters and should not be exported through the Extended parameter). The default is the empty string. Attributes are separated by spaces, the same as in HTML. The Microsoft Office host application doesn’t provide any means of checking the syntax of passed attributes.

ScriptText Optional String. Specifies the text contained in a block of script. The default is the empty string. The Microsoft Office host application doesn’t check the syntax of the script.

Remarks

A shape associated with a script block isn’t exported or printed as a shape in HTML; only the script block gets exported.

You cannot use the Add method to add a script anchor to a PowerPoint slide range that contains more than one slide.

Add method as it applies to the SignatureSet object.

Returns a Signature object that represents a new e-mail signature.

expression.Add

expression Required. An expression that returns one of the above objects.

Add method as it applies to the ODSOFilters object.

Adds a new filter to the ODSOFilters collection.

expression.Add(Column, Comparison, Conjunction, bstrCompareTo, DeferUpdate)

expression Required. An expression that returns one of the above objects.

Column Required String. The name of the table in the data source.

MsoFilterComparison

MsoFilterComparison can be one of these MsoFilterComparison constants.
msoFilterComparisonContains
msoFilterComparisonEqual
msoFilterComparisonGreaterThan
msoFilterComparisonGreaterThanEqual
msoFilterComparisonIsBlank
msoFilterComparisonIsNotBlank
msoFilterComparisonLessThan
msoFilterComparisonLessThanEqual
msoFilterComparisonNotContains
msoFilterComparisonNotEqual

MsoFilterConjunction

MsoFilterConjunction can be one of these MsoFilterConjunction constants.
msoFilterConjunctionAnd
msoFilterConjunctionOr

bstrCompareTo Optional String. If the Comparison argument is something other than msoFilterComparisonIsBlank or msoFilterComparisonIsNotBlank, a string to which the data in the table is compared.

DeferUpdate Optional Boolean. Default is False.

Add method as it applies to the AnswerWizardFiles object.

Creates a new reference (a String value) to an Answer Wizard file and adds it to the AnswerWizardFiles collection.

expression.Add(FileName)

expression Required. An expression that returns an AnswerWizardFiles collection.

FileName Required String. The fully qualified path to the specified Answer Wizard file.

Add method as it applies to the FileTypes object.

Adds a new file type to a file search.

expression.Add(FileType)

expression Required. An expression that returns one of the above objects.

MsoFileType

MsoFileType can be one of these MsoFileType constants.
msoFileTypeAllFiles
msoFileTypeBinders
msoFileTypeCalendarItem
msoFileTypeContactItem
msoFileTypeCustom
msoFileTypeDatabases
msoFileTypeDataConnectionFiles
msoFileTypeDesignerFiles
msoFileTypeDocumentImagingFiles
msoFileTypeExcelWorkbooks
msoFileTypeJournalItem
msoFileTypeMailItem
msoFileTypeNoteItem
msoFileTypeOfficeFiles
msoFileTypeOutlookItems
msoFileTypePhotoDrawFiles
msoFileTypePowerPointPresentations
msoFileTypeProjectFiles
msoFileTypePublisherFiles
msoFileTypeTaskItem
msoFileTypeTemplates
msoFileTypeVisioFiles
msoFileTypeWebPages
msoFileTypeWordDocuments

Add method as it applies to the PropertyTests object.

Adds a PropertyTest object to the PropertyTests collection.

expression.Add(Name, Condition, Value, SecondValue, Connector)

expression Required. An expression that returns a PropertyTests object.

Name Required String. The name of the property criterion. The name corresponds to a value in the Property box in the Find dialog box, which you open from the Tools menu in the application's Open dialog box (File menu).

MsoCondition

MsoCondition can be one of these MsoCondition constants.
msoConditionAnyNumberBetween
msoConditionAnytime
msoConditionAnytimeBetween
msoConditionAtLeast
msoConditionAtMost
msoConditionBeginsWith
msoConditionDoesNotEqual
msoConditionEndsWith
msoConditionEquals
msoConditionEqualsCompleted
msoConditionEqualsDeferred
msoConditionEqualsHigh
msoConditionEqualsInProgress
msoConditionEqualsLow
msoConditionEqualsNormal
msoConditionEqualsNotStarted
msoConditionEqualsWaitingForSomeoneElse
msoConditionFileTypeAllFiles
msoConditionFileTypeBinders
msoConditionFileTypeCalendarItem
msoConditionFileTypeContactItem
msoConditionFileTypeDatabases
msoConditionFileTypeDataConnectionFiles
msoConditionFileTypeDesignerFiles
msoConditionFileTypeDocumentImagingFiles
msoConditionFileTypeExcelWorkbooks
msoConditionFileTypeJournalItem
msoConditionFileTypeMailItem
msoConditionFileTypeNoteItem
msoConditionFileTypeOfficeFiles
msoConditionFileTypeOutlookItems
msoConditionFileTypePhotoDrawFiles
msoConditionFileTypePowerPointPresentations
msoConditionFileTypeProjectFiles
msoConditionFileTypePublisherFiles
msoConditionFileTypeTaskItem
msoConditionFileTypeTemplates
msoConditionFileTypeVisioFiles
msoConditionFileTypeWebPages
msoConditionFileTypeWordDocuments
msoConditionFreeText
msoConditionIncludes
msoConditionIncludesFormsOf
msoConditionIncludesNearEachOther
msoConditionIncludesPhrase
msoConditionInTheLast
msoConditionInTheNext
msoConditionIsExactly
msoConditionIsNo
msoConditionIsNot
msoConditionIsYes
msoConditionLastMonth
msoConditionLastWeek
msoConditionLessThan
msoConditionMoreThan
msoConditionNextMonth
msoConditionNextWeek
msoConditionNotEqualToCompleted
msoConditionNotEqualToDeferred
msoConditionNotEqualToHigh
msoConditionNotEqualToInProgress
msoConditionNotEqualToLow
msoConditionNotEqualToNormal
msoConditionNotEqualToNotStarted
msoConditionNotEqualToWaitingForSomeoneElse
msoConditionOn
msoConditionOnOrAfter
msoConditionOnOrBefore
msoConditionThisMonth
msoConditionThisWeek
msoConditionToday
msoConditionTomorrow
msoConditionYesterday

Value Optional Variant. The value of the search criterion.

SecondValue Optional Variant. An upper value for the search range. You can use this argument only if Condition is msoConditionAnyTimeBetween or msoConditionAnyNumberBetween.

MsoConnector

MsoConnector can be one of these MsoConnector constants.
msoConnectorAnddefault
msoConnectorOr

Add method as it applies to the SearchFolders object.

Adds a search folder to a file search.

expression.Add(ScopeFolder)

expression Required. An expression that returns one of the above objects.

ScopeFolder Required ScopeFolder object. The folder to add to the search.

Example

As it applies to the AnswerWizardFiles object.

This example prepares the Answer Wizard to accept a custom file list and adds two custom Answer Wizard files. First, the example clears the file list, and then it adds two custom Answer Wizard files and checks the file count and the file names to ensure that the files were added correctly.

  Dim customAnswerWizard As AnswerWizard
Set customAnswerWizard = Application.AnswerWizard

customAnswerWizard.ClearFileList
customAnswerWizard.Files.Add ("c:\awfiles\custom_1.aw")
customAnswerWizard.Files.Add ("c:\awfiles\custom_2.aw")

If customAnswerWizard.Files.Count = 2 Then
    MsgBox "Files " & customAnswerWizard.Files.Item(1) & _
    " and " & customAnswerWizard.Files(2) & _
    " were added sucessfully."
End If

As it applies to the CommandBarControls object.

This example creates a custom editing toolbar that contains buttons (controls) for cutting, copying, and pasting.

  Dim customBar As CommandBar
Dim newButton As CommandBarButton
Set customBar = CommandBars.Add("Custom")
Set newButton = customBar.Controls _
    .Add(msoControlButton, CommandBars("Edit") _
    .Controls("Cut").Id)
Set newButton = customBar.Controls _
    .Add(msoControlButton, CommandBars("Edit") _
    .Controls("Copy").Id)
Set newButton = customBar.Controls _
    .Add(msoControlButton, CommandBars("Edit") _
    .Controls("Paste").Id)
customBar.Visible = True

As it applies to the DocumentProperties object.

This example, which is designed to run in Microsoft Word, adds three custom document properties to the DocumentProperties collection.

  With ActiveDocument.CustomDocumentProperties
    .Add Name:="CustomNumber", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeNumber, _
        Value:=1000
    .Add Name:="CustomString", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeString, _
        Value:="This is a custom property."
    .Add Name:="CustomDate", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeDate, _
        Value:=Date
End With

As it applies to the PropertyTests object.

This example adds two property tests to the search criteria. The first test is that the files must be Microsoft Word documents, and the second test is that they must have been modified between January 1, 1996, and June 30, 1996. The example also displays a message box that shows the total number of files found, if any, and the name of each file found.

  Set fs = Application.FileSearch
fs.NewSearch
With fs.PropertyTests
    .Add Name:="Files of Type", _
        Condition:=msoConditionFileTypeWordDocuments, _
        Connector:=msoConnectorOr
    .Add Name:="Last Modified", _
        Condition:=msoConditionAnytimeBetween, _
        Value:="1/1/98", SecondValue:="6/30/98", _
        Connector:=msoConnectorAnd
End With
If fs.Execute() > 0 Then
        For i = 1 To fs.FoundFiles.Count
            strFound = strFound & fs.FoundFiles(i) & vbCrLf
        Next i
        MsgBox "Search found the following " _
            & fs.FoundFiles.Count & _
            " file(s):" & vbCrLf & strFound
Else
    MsgBox "There were no files found."
End If

As it applies to the Scripts object.