What's New for Microsoft Office Developers

Extensive changes have been made to the Microsoft Office Visual Basic object model to support new and improved features in shared components. Many objects, properties, methods, and events have been added.

New Language Elements

The following topics provide lists of language elements that are new in Office:

New Objects

New Properties (by Object)

New Properties (Alphabetic List)

New Methods

New Events


Microsoft Office Objects

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

PropertyTests collection (PropertyTest object)

DocumentProperties collection (DocumentProperty object)

HTMLProjectItems collection (HTMLProjectItem) object

COMAddIns collection (COMAddIn) object

AnswerWizard collection (AnswerWizardFiles object)

Scripts collection (Script) object

WebPageFonts collection (WebPageFont)

Legend

yellow box Object and collection
bluebox Object only


Overview of the Office Assistant

The Office Assistant, the Office Assistant balloon, and all the items inside the balloon are controlled programmatically through the objects, properties, and methods of the Assistant object.

The following illustration shows the Office Assistant, the Office Assistant balloon, and all the programmable objects inside the balloon.

The Office Assistant, a Balloon object, and the programmable elements inside the balloon

For information about how you can make design-time and run-time changes to the Office Assistant, see the following topics:

Using the Office Assistant

Creating and Modifying Balloons

Making Run-Time Modifications to Balloons


 Overview of Command Bars

Overview of Command Bars

In Microsoft Office, toolbars, menu bars, and shortcut menus are all controlled programmatically as one type of object: command bars. All the following items are represented in Visual Basic for Applications by CommandBar objects:

  • Menu bars, toolbars, and shortcut menus

  • Menus on menu bars and toolbars

  • Submenus on menus, submenus, and shortcut menus

You can modify any built-in menu bar or toolbar, and you can create and modify custom toolbars, menu bars, and shortcut menus to deliver with your Visual Basic application. You present the features of your application as individual buttons on toolbars or as groups of command names on menus. Because toolbars and menus are both command bars, you use the same kind of controls on both of them. For example, the docked toolbar shown in the following illustration contains three buttons.

A docked toolbar containing three buttons

The menu shown in the following illustration contains the same three commands as in the previous illustration, but here they're displayed as menu items.

A menu containing three menu items

In Microsoft Office, menu bars and toolbars can both contain menus. The floating toolbar shown in the following illustration contains three buttons, and it also contains a menu with the same three commands displayed as menu items.

A floating toolbar containing three buttons and a menu with three menu items

In Visual Basic, buttons and menu items are represented by CommandBarButton objects. The pop-up controls that display menus and submenus are represented by CommandBarPopup objects. In the following illustration, the control named "Menu" and the control named "Submenu" are both pop-up controls that display a menu and a submenu, respectively. Both the menu and the submenu are unique CommandBar objects with their own set of controls.

Popup controls that display a menu and a submenu

In Microsoft Office, you can also add text boxes, drop-down list boxes, and combo boxes to any command bar. These three types of controls are all represented in Visual Basic by CommandBarComboBox objects.

Note Although they share similar appearances and behaviors, command bar controls and ActiveX controls aren't the same. You cannot add ActiveX controls to command bars, and you cannot add command bar controls to documents or forms.

The built-in command bar controls in container applications are also represented in Visual Basic by CommandBarButton, CommandBarPopup, and CommandBarComboBox objects, even though their appearances and behaviors may be more complex than the controls you can add yourself. Although you can modify the location and appearance of built-in controls, you cannot modify their built-in behavior. You can, however, assign a custom macro to any built-in control to completely replace its built-in behavior.


Using Command Bars

In general, to create or modify toolbars, menu bars, and shortcut menus that you want to deliver with your Visual Basic application, you should use the customization features of the container application. Changes made to toolbars, menu bars, and shortcut menus using the features of the container application are known as "design-time" changes. For information about using the container application to make design-time changes, see the online Help for that application.

You can add and modify toolbars, menu bars, and shortcut menus (and their component parts) by using the CommandBars portion of the Microsoft Office object model in Visual Basic code. You can write code that runs once to create toolbars and menu bars; in effect, the code simulates making design-time changes. In some container applications, however, you may be required to use a combination of this kind of Visual Basic code and the customization interface to design your Visual Basic application. The following are some common areas where you must use a combination of code and the container application's interface:

  • If your container application doesn't provide an interface for adding or modifying edit boxes, drop-down list boxes, or combo boxes on toolbars, you must use Visual Basic code to add and design one of these controls.

  • If your container application provides an interface for creating toolbars but doesn't provide one for creating a new menu bar, you'll need to create a menu bar by using Visual Basic. After you've created the menu bar in Visual Basic, you can design menus on that menu bar by using the container application's interface.

  • If your container application doesn't provide a way to display custom shortcut menus while the customization interface is displayed, you must use Visual Basic code to modify those shortcut menus.

You can also write code that exists in your Visual Basic application to make changes to toolbars and menu bars while your application is running (for example, you can write code to disable a command on a menu bar under certain conditions, or to add buttons to a toolbar in response to a user's actions). Changes brought about by your code while your Visual Basic application is running are known as "run-time" changes.

The following topics provide information about how you can make design-time and run-time changes to toolbars and menu bars from your Visual Basic code.

Adding and Modifying Toolbars

Adding and Managing Menu Bars and Menu Items

Adding and Displaying Shortcut Menus


 Adding and Modifying Toolbars

Adding and Modifying Toolbars

All host applications have an extensive interface for adding and designing custom toolbars (adding built-in buttons, adding macros as buttons, even adding pop-up controls to toolbars). The design-time changes you'll usually make from Visual Basic code are ones that add or modify combo box controls. Otherwise, working with toolbars in code is almost completely limited to making run-time changes (changing the button state, changing the button appearance, changing the button action, and so on).

Making run-time modifications to toolbars

There are several modifications you can make to a toolbar at run time. One of these modifications is to change the state of a command bar button on the toolbar. Each button control has two active states: pushed (True) and not pushed (False). To change the state of a button control, use the appropriate constant for the State property, as explained in the table later in this topic.

Another modification you can make at run time is to change the appearance or action of a button. To change the appearance of a button but not its action, use the CopyFace and PasteFace methods. These methods are useful if you want to copy the face of a particular button onto the Clipboard or import it into another application to change some of its features. Use the PasteFace method to transfer the button image from the Clipboard onto a specific button.

To change a button's action to a function you've developed, assign the custom procedure name to the button's OnAction property.

The following table lists the most common properties and methods for changing the state, appearance, or action of a button.

Property or method | Description
CopyFace, PasteFace | Copies or pastes the image on the face of a button. Use the CopyFace method to copy the face of the specified button to the Clipboard. Use the PasteFace method to paste the contents of the Clipboard onto the face of the specified button. The PasteFace method will fail if the Clipboard is empty. If the image on the Clipboard is too large for the button face, the image won't be scaled down. Generally, it's more convenient to copy and paste a button face at design time, but you can also make changes to a button face at run time. You can also use the FaceId property to assign a different built-in button face to a button.
Id | Specifies the value that represents the button's built-in functionality. For example, a button that copies highlighted text to the Clipboard has an Id value of 19.
State | Specifies the appearance, or state, of the button. Can be one of the following MsoButtonState constants: msoButtonDown, msoButtonMixed, or msoButtonUp.
Style | Specifies whether the button face displays its icon or its caption. Can be one of the following MsoButtonStyle constants: msoButtonAutomatic, msoButtonIcon, msoButtonCaption, msoButtonIconAndCaption, msoButtonIconAndCaptionBelow, msoButtonIconAndWrapCaption, msoButtonIconAndWrapCaptionBelow, or msoButtonWrapCaption.
OnAction | Specifies the procedure to be run when the user clicks a button, displays a menu, or changes the contents of a combo box control.
Visible | Specifies whether the control is to be displayed or hidden from the user.
Enabled | Enables or disables a command bar; the name of a disabled command bar won't appear in the list of available command bars.

The following example creates a new command bar containing a single command bar button. By using the OnAction property of the CommandBarButton object, you can use the CopyFace method to copy the button face of the built-in Open button to the Clipboard, and then you can use the PasteFace method to paste the face onto the existing button. This changes the appearance of the command bar button at run time.

Sub testAddModifyToolbars1()
Set myBar = CommandBars _
    .Add(Name:="ChangingButton", Position:=msoBarTop, _
    Temporary:=True)
myBar.Visible = True
Set oldControl = myBar.Controls _
    .Add(Type:=msoControlButton, _
    ID:=CommandBars("Standard").Controls("Copy").Id)
oldControl.OnAction = "changeFaces"
End Sub

Sub changeFaces()
Set newControl = CommandBars.FindControl _
    (Type:=msoControlButton, _
    ID:=CommandBars("Standard").Controls("Paste").Id)
newControl.CopyFace
Set oldControl = _
CommandBars("ChangingButton").Controls(1)
oldControl.PasteFace
End Sub

Adding and modifying combo box controls

Edit boxes, drop-down list boxes, and combo boxes are powerful new controls you can add to toolbars in your Visual Basic application. However, most container applications require that you use Visual Basic code to design these controls. To design a combo box control, you use the properties and methods described in the following table.

Property or method | Description
Add | Adds a combo box control to a command bar by specifying one of the following MsoControlType constants for the Type argument: msoControlEdit, msoControlDropdown, or msoControlComboBox.
AddItem | Adds an item to the drop-down list portion of a drop-down list box or combo box. You can specify the index number of the new item in the existing list, but if this number is larger than the number of items in the list, the AddItem method fails.
Caption | Specifies the label for the combo box control. This is the label that's displayed next to the control if you set the Style property to msoComboLabel.
Style | Specifies whether the caption for the specified control will be displayed next to the control. Can be either of the following MsoComboStyle constants: msoComboLabel (the label is displayed) or msoComboNormal (the label isn't displayed).
OnAction | Specifies the procedure to be run when the user changes the contents of the combo box control.

The following example adds a combo box to a custom toolbar and assigns the macro named "ScrollToQuarter" to the combo box.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
myBar.Visible = True
Set newCombo = myBar.Controls _
    .Add(Type:=msoControlComboBox)
With newCombo
    .AddItem "Q1"
    .AddItem "Q2"
    .AddItem "Q3"
    .AddItem "Q4"
    .Style = msoComboNormal
    .OnAction = "ScrollToQuarter"
End With

While your application is running, the procedure assigned to the OnAction property of the combo box control is called each time the user changes the control. In the procedure, you can use the ActionControl property of the CommandBar object to find out which control was changed and to return the changed value. The ListIndex property will return the item typed or selected in the combo box.


Adding and Managing Menu Bars and Menu Items

Some container applications don't provide a way for you to create new menu bars, so you'll need to create menu bars by using Visual Basic. After you've created a menu bar in Visual Basic, you can customize it by using the container application's interface or by using Visual Basic.

Adding menu bars at run time

When you add a menu bar to an application at run time, you use the Add method for the CommandBars collection and specify True for the menubar argument. The following example adds a menu bar that cannot be moved. The example also docks this menu bar along the right side of the application window. The new menu bar becomes active whenever the user presses the ALT key.

Set menubar = CommandBars.Add _
    (Name:="mBar", Position:=msoBarRight, MenuBar:=True)
With menubar
    .Protection = msoBarNoMove
    .Visible = True
End With

Making run-time modifications to menu bars

You can make modifications to the both the menu bar and the controls on that menu bar at run time. The changes you make to the menu bar may affect its appearance or its position; changes you make to the controls depend on the control type. The properties and methods listed in the following table are the most common ones used to modify menu bars at run time.

Property or method | Description
Add | Adds a menu bar by using the Add method of the CommandBars collection and specifying True for the menubar argument.
Enabled | If this property is set to True, the user can make the specified menu bar visible, using Visual Basic code. If this property is set to False, the user cannot make the menu bar visible, but it will appear in the list of available command bars.
Protection | Make it possible for you to protect the menu bar from specific user actions. Can be one of or a combination of the following MsoBarProtection constants: msoBarNoChangeDock, msoBarNoChangeVisible, msoBarNoCustomize, msoBarNoHorizontalDock, msoBarNoMove, msoBarNoProtection, msoBarNoResize, and msoBarNoVerticalDock.
Position | Specifies the position of the new menu bar, relative to the application window. Can be one of the following MsoBarPosition constants: msoBarLeft, msoBarTop, msoBarRight, msoBarBottom, msoBarFloating, msoBarPopup (used to create shortcut menus), or msoBarMenuBar ((Macintosh only)).
Visible | Specifies whether the control will be displayed or hidden from the user. If the control is hidden from the user, the menu bar name will still appear in the list of available command bars.

The following example hides the active menu bar and replaces it with a temporary menu bar that's docked along the right side of the application window and is protected from the user.

Set oldMbar = CommandBars.ActiveMenuBar
Set newMbar = CommandBars.Add _
(Name:="newMenubar", Position:=msoBarRight, _
MenuBar:=True, temporary:=True)
With newMbar
    .Visible = True
    .Protection = msoBarNoMove
End With

Merging menu bars at run time

If you have custom menu bars in an application that's intended to be an add-in, you may want to specify how the controls will be represented in the container application. You can use the OLEMenuGroup property of the CommandBarPopup object to specify how the menu bar merging will occur.

If either the container application or the server doesn't implement command bars, "non-Office" merging will occur: the menu bar will be merged, along with all the toolbars from the server, and none of the toolbars from the container application will be merged. You can also use the OLEUsage property to specify how menu bar merging will occur.

If both the container application and the server implement command bars, "Office-in-Office" merging will occur: the command bar controls are embedded in the Office application, control by control. Both of these properties (OLEMenuGroup and OLEUsage) are relevant only for pop-up controls on menu bars, because menus are considered on the basis of their menu group category.

Making run-time modifications to menu items

The range of modifications you can make to a menu item depends on the control type. Generally, buttons are enabled, or hidden. Edit boxes, drop-down list boxes, and combo boxes are more versatile in that you can add or delete items from the list, and you can determine the action performed by looking at the value selected. You can change the action of any control to either a built-in or custom function.

The following table lists the most common properties and methods for changing the state, action, or contents of a control.

Property or method | Purpose
Add | Adds a menu item to a command bar. Can be one of the following MsoControlType constants for the Type argument for a built-in control: msoControlButton, msoControlEdit, msoControlDropdown, or msoControlComboBox.
AddItem | Adds an item to the drop-down list portion of a drop-down list box or combo box. You can specify the index number of the new item in the existing list, but if this number is larger than the number of items in the list, the AddItem method fails.
Style | Specifies whether (and if so, how) the button face displays its icon or its caption, or both. Can be one of the following MsoButtonStyle constants: msoButtonAutomatic, msoButtonIcon, msoButtonCaption, msoButtonIconAndCaption, msoButtonIconAndCaptionBelow, msoButtonIconAndWrapCaption, msoButtonIconAndWrapCaptionBelow, or msoButtonWrapCaption.
OnAction | Specifies the procedure to be run whenever the user changes the value of the specified control.
Visible | Specifies whether the control will be displayed or hidden from the user.

This following example adds a temporary pop-up control named "Custom" at the end of the active menu bar, and then it adds a button control named "Import" to the Custom pop-up command bar.

Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _
    Temporary:=True)
newMenu.Caption = "Custom"
Set ctrl1 = newMenu.Controls _
    .Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "Import"
ctrl1.TooltipText = "Import"
ctrl1.Style = msoButtonCaption


Adding and Displaying Shortcut Menus

A shortcut menu is a floating command bar that the user displays by right-clicking. It can contain the same control types as a command bar, and the controls behave in the same way as on a command bar. In most applications, however, you cannot create or modify shortcut menus from the application's interface. Therefore, you need to create and modify your shortcut menus at run time.

Adding shortcut menus at run time

The only difference between shortcut menus and other toolbars is that when you create the shortcut menu with the Add method, you must specify msoBarPopUp as the position argument. The following example creates a new shortcut menu, adds two controls (with captions) to it, and then uses the ShowPopup method to display the new menu.

Set copyAndPasteMenu = CommandBars.Add( _
    Name:="Custom", Location:=msoBarPopup, _
    Temporary:=True)
Set copy = copyAndPasteMenu.Controls.Add
With copy
    .FaceId = CommandBars("Standard").Controls("Copy").Id
    .Caption = "Copy the selection"
End With
Set paste = copyAndPasteMenu.Controls.Add
With paste
    .FaceId = CommandBars("Standard").Controls("Paste").Id
    .Caption = "Paste from the Clipboard"
End With
copyAndPasteMenu.ShowPopup 200, 200

Displaying shortcut menus

Use the ShowPopup method to display shortcut menus, as demonstrated in the preceding example.

If the container application supports assigning event procedures to user actions, you can display a shortcut menu in response to a right-click event. However, not all applications support event procedures. Check the documentation for your container application to see whether the application supports event procedures.

Making run-time modifications to shortcut menus

Any changes you make to a shortcut menu must be made at run time, and the changes you make will generally be limited to changing the appearance or action of the controls on the menu. For more information about adding and managing menu items, see Adding and Managing Menu Bars and Menu Items.


OLE Programmatic Identifiers

You can use an OLE programmatic identifier (sometimes called a ProgID) to create an Automation object. The following tables list OLE programmatic identifiers for ActiveX controls, Microsoft Office applications, and Microsoft Office Web Components.

ActiveX Controls

Microsoft Access

Microsoft Excel

Microsoft Graph

Microsoft Office Web Components

Microsoft Outlook

Microsoft PowerPoint

Microsoft Word

ActiveX Controls

To create the ActiveX controls listed in the following table, use the corresponding OLE programmatic identifier.

To create this control | Use this identifier
CheckBox | Forms.CheckBox.1
ComboBox | Forms.ComboBox.1
CommandButton | Forms.CommandButton.1
Frame | Forms.Frame.1
Image | Forms.Image.1
Label | Forms.Label.1
ListBox | Forms.ListBox.1
MultiPage | Forms.MultiPage.1
OptionButton | Forms.OptionButton.1
ScrollBar | Forms.ScrollBar.1
SpinButton | Forms.SpinButton.1
TabStrip | Forms.TabStrip.1
TextBox | Forms.TextBox.1
ToggleButton | Forms.ToggleButton.1

Microsoft Access

To create the Microsoft Access objects listed in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Access available on the machine where the macro is running.

To create this object | Use one of these identifiers
Application | Access.Application, Access.Application.9
CurrentData | Access.CodeData, Access.CurrentData
CurrentProject | Access.CodeProject, Access.CurrentProject
DefaultWebOptions | Access.DefaultWebOptions

Microsoft Excel

To create the Microsoft Excel objects listed in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Excel available on the machine where the macro is running.

To create this object | Use one of these identifiers | Comments
Application | Excel.Application, Excel.Application.9 |
Workbook | Excel.AddIn |
Workbook | Excel.Chart, Excel.Chart.8 | Returns a workbook containing two worksheets; one for the chart and one for its data. The chart worksheet is the active worksheet.
Workbook | Excel.Sheet, Excel.Sheet.8 | Returns a workbook with one worksheet.

Microsoft Graph

To create the Microsoft Graph objects listed in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Graph available on the machine where the macro is running.

To create this object | Use one of these identifiers
Application | MSGraph.Application, MSGraph.Application.8
Chart | MSGraph.Chart, MSGraph.Chart.8

Microsoft Office Web Components

To create the Microsoft Office Web Components objects listed in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Microsoft Office Web Components available on the machine where the macro is running.

To create this object | Use one of these identifiers
ChartSpace | OWC.Chart, OWC.Chart.9
DataSourceControl | OWC.DataSourceControl, OWC.DataSourceControl.9
ExpandControl | OWC.ExpandControl, OWC.ExpandControl.9
PivotTable | OWC.PivotTable, OWC.PivotTable.9
RecordNavigationControl | OWC.RecordNavigationControl, OWC.RecordNavigationControl.9
Spreadsheet | OWC.Spreadsheet, OWC.Spreadsheet.9

Microsoft Outlook

To create the Microsoft Outlook object given in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Outlook available on the machine where the macro is running.

To create this object | Use one of these identifiers
Application | Outlook.Application, Outlook.Application.9

Microsoft PowerPoint

To create the Microsoft PowerPoint object given in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of PowerPoint available on the machine where the macro is running.

To create this object | Use one of these identifiers
Application | PowerPoint.Application, PowerPoint.Application.9

Microsoft Word

To create the Microsoft Word objects listed in the following table, use one of the corresponding OLE programmatic identifiers. If you use an identifier without a version number suffix, you create an object in the most recent version of Word available on the machine where the macro is running.

To create this object | Use one of these identifiers
Application | Word.Application, Word.Application.9
Document | Word.Document, Word.Document.9, Word.Template.8
Global | Word.Global


Change Event

Occurs when the end user changes the selection in a command bar combo box.

Syntax

Private Sub CommandBarComboBox_Change

(ByVal Ctrl As CommandBarComboBox)

Remarks

The Change event is recognized by the CommandBarComboBox object. To return the Change event for a particular CommandBarComboBox control, use the WithEvents keyword to declare a variable, and then set the variable to the CommandBarComboBox control. When the Change event is triggered, it executes the macro or code that you specified with the OnAction property of the control.


Change Event Example

The following example creates a command bar with a CommandBarComboBox control containing four selections. The combo box responds to user interaction through the CommandBarComboBox_Change event.

Private ctlComboBoxHandler As New ComboBoxHandler
Sub AddComboBox()

    Set HostApp = Application

    Dim newBar As Office.CommandBar
    Set newBar = HostApp.CommandBars.Add(Name:="Test CommandBar", Temporary:=True)
    Dim newCombo As Office.CommandBarComboBox
    Set newCombo = newBar.Controls.Add(msoControlComboBox)
    With newCombo
        .AddItem "First Class", 1
        .AddItem "Business Class", 2
        .AddItem "Coach Class", 3
        .AddItem "Standby", 4
        .DropDownLines = 5
        .DropDownWidth = 75
        .ListHeaderCount = 0
    End With
    ctlComboBoxHandler.SyncBox newCombo
    newBar.Visible = True

End Sub

The preceding example relies on the following code, which is stored in a class module in the VBA project.

Private WithEvents ComboBoxEvent As Office.CommandBarComboBox

Public Sub SyncBox(box As Office.CommandBarComboBox)
    Set ComboBoxEvent = box
    If Not box Is Nothing Then
        MsgBox "Synced " & box.Caption & " ComboBox events."
    End If

End Sub

Private Sub Class_Terminate()
    Set ComboBoxEvent = Nothing
End Sub

Private Sub ComboBoxEvent_Change(ByVal Ctrl As Office.CommandBarComboBox)
    Dim stComboText As String

    stComboText = Ctrl.Text

        Select Case stComboText
        Case "First Class"
            FirstClass
        Case "Business Class"
            BusinessClass
        Case "Coach Class"
            CoachClass
        Case "Standby"
            Standby
    End Select

End Sub
Private Sub FirstClass()
    MsgBox "You selected First Class reservations"
End Sub
Private Sub BusinessClass()
    MsgBox "You selected Business Class reservations"
End Sub
Private Sub CoachClass()
    MsgBox "You selected Coach Class reservations"
End Sub
Private Sub Standby()
    MsgBox "You chose to fly standby"
End Sub


Click Event

Occurs when the user clicks a CommandBarButton object.

Syntax

Private Sub CommandBarButton_Click

(ByVal Ctrl As CommandBarButton,

ByVal CancelDefault As Boolean)

The syntax for the Click event includes the two arguments described in the following table.

Argument | Description
Ctrl | Required CommandBarButton. Denotes the CommandBarButton control that initiated the event.
CancelDefault | Required Boolean. False if the default behavior associated with the CommandBarButton control occurs, unless it’s canceled by another process or add-in.

Remarks

The Click event is recognized by the CommandBarButton object. To return the Click event for a particular CommandBarButton control, use the WithEvents keyword to declare a variable, and then set the variable to the control.


Click Event Example

The following example creates a new command bar button on the File menu of the host application that enables the user to save a workbook as a comma-separated value file. (This example works in all applications, but the context of saving as CSV is applicable to Microsoft Excel.)

Private HostApp As Object

Sub createAndSynch()
    Dim iIndex As Integer
    Dim iCount As Integer
    Dim fBtnExists As Boolean

    Dim obCmdBtn As Object

    On Error GoTo errHandler

    Set HostApp = Application

    Dim barHelp As Office.CommandBar
    Set barHelp = Application.CommandBars("File")
    fBtnExists = False
    iCount = barHelp.Controls.Count
    For iIndex = 1 To iCount
        If barHelp.Controls(iIndex).Caption = "Save As CSV (Comma Delimited)" Then fBtnExists = True

    Next
    Dim btnSaveAsCSV As Office.CommandBarButton
    If fBtnExists Then
        Set btnSaveAsCSV = barHelp.Controls("Save As CSV (Comma Delimited)")
    Else
        Set btnSaveAsCSV = barHelp.Controls.Add(msoControlButton)
        btnSaveAsCSV.Caption = "Save As CSV (Comma Delimited)"
    End If

    btnSaveAsCSV.Tag = "btn1"
    btnSaveAsCSVHandler.SyncButton btnSaveAsCSV
    Exit Sub

errHandler:
    ' Insert error handling code here
End Sub

The preceding example relies on the following code, which is stored in a class module in the VBA project.

Private WithEvents ButtonClickEvent As Office.CommandBarButton

Private Sub ButtonClickEvent_Click(ByVal Ctrl As Office.CommandBarButton, _
    CancelDefault As Boolean)
    ActiveWorkbook.SaveAs "MyWorkbook.csv", xlCSV
    CancelDefault = True
End Sub

Public Sub SyncButton(btn As Office.CommandBarButton)
    Set ButtonClickEvent = btn
    If Not btn Is Nothing Then
        MsgBox "Synced '" & btn.Caption & "' button events."
    End If

End Sub

Private Sub Class_Terminate()
    Set ButtonClickEvent = Nothing
End Sub


OnUpdate Event

Occurs when any change is made to a command bar.

Syntax

Private Sub CommandBars_OnUpdate()

Remarks

The OnUpdate event is recognized by the CommandBar object and all command bar controls. The event is triggered by any change to a command bar or command bar control or any change to the state of a command bar or command bar control. These changes can occur due to a text or cell selection, for example. Since a large number of OnUpdate events can occur during normal uage, developers should exercise caution when using this event. It is strongly recommended that this event be used primarily for checking that a custom command bar has been added or removed by a COMAddIn. For more information on using events with COM add ins, see the chapter "Add-ins, Templates, Wizards, and Libraries" in the Microsoft Office 2000/Visual Basic Programmer's Guide.


New Methods

Methods that have been added to existing objects in Microsoft Office are listed in the following table.

Method | Object
FindControls | CommandBars


ActivateWizard Method

Resumes or suspends Office Assistant Help during a custom wizard.

Note You should use this method only with the StartWizard method.

Syntax

expression.ActivateWizard(WizardID, Act, Animation)

expression Required. An expression that returns an Assistant object.

WizardID Required Long. The number returned by the StartWizard method.

Act Required Variant. Specifies the change to the Office Assistant Help session. Can be one of the following MsoWizardActType constants: msoWizardActActive, msoWizardActInactive, msoWizardActResume, or msoWizardActSuspend.

Animation Optional Variant. The animation the Office Assistant performs when it is suspended or resumed.


ActivateWizard Method Example

This example suspends the wizard session that was started with the StartWizard method. The variable lHelpForWiz was set to the return value of the StartWizard method.

Assistant.ActivateWizard WizardID:=lHelpForWiz, _
   Act:=msoWizardActSuspend, Animation:=msoAnimationGoodbye


Add Method

Adds an object to a collection. Select one of the following collections to see a detailed description of the Add method for that collection.

AnswerWizardFiles

CommandBarControls

CommandBars

DocumentProperties

PropertyTests

Scripts


Add Method (AnswerWizardFiles Collection Object)

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

Syntax

expression.Add (Filename)

expression An expression that returns an AnswerWizardFiles collection.

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


Add Method (AnswerWizardFiles Collection Object) Example

This example prepares the AnswerWizard to accept a custom file list and adds two custom AnswerWizard files. First, the example clears the file list, and then it adds two custom AnswerWizard 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


 Add Method (CommandBarControls Collection)

Add Method (CommandBarControls Collection)

Creates a new command bar control and adds it to the collection of controls on the specified command bar. Returns a CommandBarButton, CommandBarComboBox, or CommandBarPopup object.

Syntax

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 (CommandBarControls Collection) Example

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


 Add Method (CommandBars Collection)

Add Method (CommandBars Collection)

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

Syntax

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 (CommandBars Collection) Example

This example adds a top-level command bar named "Custom”. The example also adds a built-in paste button to the command bar.

Set mybar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With mybar
    .Controls.Add Type:=msoControlButton, Id:= _
        CommandBars("Edit").Controls("Paste").ID
    .Visible = True
End With


Add Method (DocumentProperties Collection)

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

Syntax

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 Required Long. 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 String. 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 an Office document, you must save the document to see the change to the DocumentProperty object.


Add Method (DocumentProperties Collection) Example

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


 AddItem Method

AddItem Method

Adds a list item to the specified command bar combo box control. The combo box control must be a custom control and must be a drop-down list box or a combo box.

Note This method will fail if it's applied to an edit box or a built-in combo box control.

Syntax

expression.AddItem(Text, Index)

expression Required. An expression that returns a CommandBarComboBox object.

Text Required String. The text added to the control.

Index Optional Variant. The position of the item in the list. If this argument is omitted, the item is added to the end of the list.


AddItem Method Example

This example adds a combo box control to a command bar. Two items are added to the control, and the number of line items and the width of the combo box are set.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls.Add(Type:=msoControlComboBox, Id:=1)
With myControl
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
End With


 Clear Method

Clear Method

Removes all list items from a command bar combo box control (drop-down list box or combo box) and clears the text box (edit box or combo box).

Note This method will fail if it's applied to a built-in command bar control.

Syntax

expression.Clear

expression Required. An expression that returns a CommandBarComboBox object.


ClearFileList Method

Clears the list of files for the current AnswerWizard, including the default list of files for the Microsoft Office host application.

Syntax

expression.ClearFileList

expression An expression that returns an AnswerWizard object.

Remarks

Use this method to remove all entries from the current file list for the specified application. You can also use it to ensure that none of the default AnswerWizard files for the host application are available to users. You can then build a custom list of files by using the Add method of the AnswerWizardFiles collection.

To restore the default AnswerWizard file set for the host application, use the ResetFileList method.


ClearFileList Method Example

This example prepares the AnswerWizard to accept a custom file list and then adds two custom AnswerWizard files. First, the example clears the file list, and then it adds two custom AnswerWizard 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


Close Method

Closes the active modeless balloon. You should use this method only in callback procedures.

Syntax

expression.Close

expression Required. An expression that returns a Balloon object.


Close Method Example

This example displays a balloon that contains a button for each of three printers. Whenever the user clicks one of these buttons, the ProcessPrinter callback procedure is run and the balloon is closed.

Sub selectPrinter()
Set bln = Assistant.NewBalloon
With bln
    .Heading = "Select a Printer."
    .Labels(1).Text = "Network Printer"
    .Labels(2).Text = "Local Printer"
    .Labels(3).Text = "Local Color Printer"
    .BalloonType = msoBalloonTypeButtons
    .Mode = msoModeModeless
    .Callback = "ProcessPrinter"
    .Show
End With
End Sub

Sub ProcessPrinter(bln As Balloon, lbtn As Long, _
 lPriv As Long)
    Assistant.Animation = msoAnimationPrinting
    Select Case lbtn
    Case -1
        ' Insert network printer-specific code.
    Case -2
        ' Insert local printer-specific code.
    Case -3
        ' Insert color printer-specific code.
    End Select
    bln.Close
End Sub


 Copy Method

Copy Method

Copies a command bar control to an existing command bar.

Syntax

expression.Copy(Bar, Before)

expression Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Bar Optional Variant. A CommandBar object that represents the destination command bar. If this argument is omitted, the control is copied to the command bar where the control already exists.

Before Optional Variant. A number that indicates the position for 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 copied to the end of the command bar.


 CopyFace Method

CopyFace Method

Copies the face of a command bar button control to the Clipboard.

Syntax

expression.CopyFace

expression Required. An expression that returns a CommandBarButton object.

Remarks

Use the PasteFace method to paste the contents of the Clipboard onto a button face.


CopyFace Method Example

This example finds the built-in Open button, copies the button face to the Clipboard, and then pastes the face onto the Spelling and Grammar button.

Set myControl = CommandBars.FindControl(Type:=msoControlButton, Id:=23)
myControl.CopyFace
Set myControl = CommandBars.FindControl(Type:=msoControlButton, ID:=2)
myControl.PasteFace


Delete Method

Deletes the specified object from its collection.

Syntax 1

expression.Delete

Syntax 2

expression.Delete(Temporary)

Syntax 3

expression.Delete(Filename)

expression Required. An expression that returns a CommandBar or DocumentProperty object (Syntax 1), a CommandBarControl object (Syntax 2), or an AnswerWizardFiles object (Syntax 3).

Temporary Optional Variant. True to delete the control for the current session. The application will display the control again in the next session.

Filename Required String. The name of the file to be deleted, including the fully-qualified path, file name, and extension.

Remarks

You cannot delete a built-in document property.

For the Scripts collection, using the Delete method removes all scripts from the specified Word document, Excel worksheet, or PowerPoint slide. A script anchor is represented by a shape in the host application. Therefore, the Shape object associated with each script anchor of type msoScriptAnchor is deleted from the Shapes collection in Excel and PowerPoint and from the InlineShapes and Shapes collections in Word.


Delete Method Example

This example deletes all custom command bars that aren't visible.

foundFlag = False
delBars = 0
For Each bar In CommandBars
    If (bar.BuiltIn = False) And _
    (bar.Visible = False) Then
        bar.Delete
        foundFlag = True
        delBars = delBars + 1
    End If
Next bar
If Not foundFlag Then
    MsgBox "No command bars have been deleted."
Else
    MsgBox delBars & " custom bar(s) deleted."
End If

This example deletes a custom document property. For this example to run properly, you must have a custom DocumentProperty object named "CustomNumber".

ActiveDocument.CustomDocumentProperties("CustomNumber").Delete


EndWizard Method

Releases the variable returned by the StartWizard method.

Note You should use this method only with the StartWizard method.

Syntax

expression.EndWizard(WizardID, varfSuccess, Animation)

expression Required. An expression that returns an Assistant object.

WizardID Required Long. The number returned by the StartWizard method.

varfSuccess Required Boolean. True to indicate that the user completed the wizard successfully.

Animation Optional Variant. The animation the Office Assistant performs if varfSuccess is set to True. The default value is msoAnimationCharacterSuccessMajor.


EndWizard Method Example

This example closes the Office Assistant for a wizard session that was completed successfully by the user. The variable lHelpForWiz was assigned the return value of the StartWizard method.

Assistant.EndWizard WizardId:=lHelpForWiz, _
    varfSuccess:=True, Animation:=msoAnimationGoodbye


Execute Method

Runs a procedure associated with a command bar control or begins searching for files. Select one of the following objects to see a detailed description of the Execute method for that object.

CommandBarButton

CommandBarControl

CommandBarPopup

CommandBarComboBox

FileSearch


 Execute Method (CommandBarControl Object)

Execute Method (CommandBarControl Object)

Runs the procedure or built-in command assigned to the specified command bar control. For custom controls, use the OnAction property to specify the procedure to be run.

Syntax

expression.Execute

expression Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.


Execute Method (CommandBarControl Object) Example

This Microsoft Excel example creates a command bar and then adds a built-in command bar button control to it. The button executes the Excel AutoSum function. This example uses the Execute method to total the selected range of cells when the command bar appears.

Dim cbrCustBar As CommandBar
Dim ctlAutoSum As CommandBarButton
Set cbrCustBar = CommandBars.Add("Custom")
Set ctlAutoSum = cbrCustBar.Controls _
    .Add(msoControlButton, CommandBars("Standard") _
    .Controls("AutoSum").Id)
cbrCustBar.Visible = True
ctlAutoSum.Execute


Execute Method (FileSearch Object)

FileSearch object: Begins the search for the specified files.

Syntax 1

expression.Execute(SortBy, SortOrder, AlwaysAccurate)

expression Required. An expression that returns a FileSearch object.

SortBy Optional Variant. The method used to sort the returned files. Can be one of the following MsoSortBy constants: msoSortbyFileName, msoSortbyFileType, msoSortbyLastModified, or msoSortbySize.

SortOrder Optional Variant. The order in which the returned files are sorted. Can be either of the following MsoSortOrder constants: msoSortOrderAscending or msoSortOrderDescending.

AlwaysAccurate Optional Boolean. True to have the file search include files that have been added, modified, or deleted since the file index was last updated. The default value is True.


Execute Method (FileSearch Object) Example

This example searches for all files in the My Documents folder that end with the file name extension “.doc” and then displays the location and name of each file found. The example also sorts the list of returned file names in ascending alphabetic order.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "*.doc"
    If .Execute(SortBy:=msoSortbyFileName, _
            SortOrder:=msoSortOrderAscending) > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


FindControl Method

Returns a CommandBarControl object that fits a specified criteria.

Syntax

expression.FindControl(Type, Id, Tag, Visible, Recursive)

expression Required. An expression that returns a CommandBars object.

Type Optional Variant. The type of control. Can be one of the following MsoControlType constants:

msoControlActiveX

msoControlCustom

msoControlButton

msoControlEdit

msoControlDropdown

msoControlComboBox

msoControlButtonDropdown

msoControlSplitDropdown

msoControlGenericDropdown

msoControlGraphicCombo

msoControlSplitButtonMRUPopup

msoControlSplitExpandingGrid

 msoControlGraphicDropdown

msoControlPopup

msoControlGraphicPopup

msoControlButtonPopup

msoControlGauge

msoControlLabel

msoControlExpandingGrid

msoControlGrid

msoControlOCXDropDown

msoControlSplitButtonPopup

msoControlPane

Id Optional Variant. The identifier of the control.

Tag Optional Variant. The tag value of the control.

Visible Optional Variant. True to include only visible command bar controls in the search. The default value is False. Visible command bars include all visible toolbars and any menus that are open at the time the FindControl method is executed.

Recursive Optional Boolean. True to include the command bar and all of its pop-up subtoolbars in the search. The default value is False.

Remarks

If the CommandBars collection contains two or more controls that fit the search criteria, FindControl returns the first control that's found. If no control that fits the criteria is found, FindControl returns Nothing.


FindControls Method

Returns the CommandBarControls collection that fits the specified criteria.

Syntax

expression.FindControl(Type, Id, Tag, Visible)

expression Required. An expression that returns a CommandBars collection.

Type Optional Variant. The type of control. Can be one of the following MsoControlType constants:

msoControlActiveX

msoControlCustom

msoControlButton

msoControlEdit

msoControlDropdown

msoControlComboBox

msoControlButtonDropdown

msoControlSplitDropdown

msoControlGenericDropdown

msoControlGraphicCombo

msoControlSplitButtonMRUPopup

msoControlSplitExpandingGrid

 msoControlGraphicDropdown

msoControlPopup

msoControlGraphicPopup

msoControlButtonPopup

msoControlGauge

msoControlLabel

msoControlExpandingGrid

msoControlGrid

msoControlOCXDropDown

msoControlSplitButtonPopup

msoControlPane

Id Optional Variant. The control’s identifier.

Tag Optional Variant. The control’s tag value.

Visible Optional Variant. True to include only visible command bar controls in the search. The default value is False.

Remarks

If no controls that fits the criteria are found, the FindControls method returns Nothing.


FindControls Method Example

This example uses the FindControls method to return all members of the CommandBarControls collection that have an ID of 18 and displays (in a message box) the number of controls that meet the search criteria.

Dim myControls As CommandBarControls
Set myControls = CommandBars.FindControls(Type:=msoControlButton, ID:=18)
MsgBox "There are " & myControls.Count & _
    " controls that meet the search criteria."


Help Method

Displays the Office Assistant and the built-in "What would you like to do?" Assistant balloon for standard Office online Help.

Syntax

expression.Help

expression Required. An expression that returns an Assistant object.


Help Method Example

This example displays the built-in "What would you like to do?" Assistant balloon when the user checks the "I need more information" check box.

Set b = Assistant.NewBalloon
With b
    .Heading = "User Information"
    .Text = "Select your skill level"
    .CheckBoxes(1).Text = "Beginner."
    .CheckBoxes(2).Text = "Advanced."
    .CheckBoxes(3).Text = "I need more information."
    .Show
End With
If b.CheckBoxes(3).Checked = True Then
    Assistant.Help
End If


LoadFromFile Method

Updates the text in the Microsoft Script Editor with text from the specified file (on disk).

Syntax

expression.LoadFromFile(Filename)

expression An HTMLProjectItem object.

Filename Required String. The fully qualified path of the text file that contains the text to be loaded.


LoadFromFile Method Example

This example determines whether the specified HTML project item is open; if the item is open, the example then loads script from the specified file.

If ActiveWorkbook.HTMLProject.HTMLProjectItems _
    .Item(1).IsOpen Then
    ActiveWorkbook.HTMLProject.HTMLProjectItems _
        .Item(1).LoadFromFile ("C:\MyScript.txt")
Else
    MsgBox "The HTMLProjectItem is not open."
End If


 Move Method

Move Method

CommandBarControl object: Moves the specified command bar control to an existing command bar.

Assistant object: Moves the Office Assistant to the specified location.

Syntax 1

expression.Move(Bar, Before)

Syntax 2

expression.Move(xLeft, yTop)

expression Syntax 1: Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Syntax 2: Required. An expression that returns an Assistant object.

Bar Optional Variant. A CommandBar object that represents the destination command bar for the control. If this argument is omitted, the control is moved to the end of the same command bar (the command bar where the control currently resides).

Before Optional Variant. A number that indicates the position for the control. The control is inserted before the control currently occupying this position. If this argument is omitted, the control is inserted on the same command bar.

xLeft Required Integer. The left position of the Office Assistant window, in points.

yTop Required Integer. The top position of the Office Assistant window, in points.


Move Method Example

This example moves the first combo box control from the custom command bar named "Custom" to the position before the seventh control on that command bar. The example sets the tag to "Selection box" and assigns the control a low priority so that it will likely be dropped from the command bar if all the controls don't fit in one row.

Set allcontrols = CommandBars("Custom").Controls
For Each ctrl In allControls
    If ctrl.Type = msoControlComboBox Then
        With ctrl
            .Move Before:=7
             .Tag = "Selection box"
             .Priority = 5
         End With
         Exit For
    End If
Next

This example displays the Office Assistant in the specified location and sets several options before making it visible.

With Assistant
    .Reduced = True
    .Move xLeft:= 400, yTop:= 300
    .MoveWhenInTheWay = True
    .TipOfDay = True
    .Visible = True
    .Animation = msoAnimationGreeting
End With


NewSearch Method

Resets all the search criteria settings to their default settings.

Syntax

expression.NewSearch

expression Required. An expression that returns a FileSearch object.

Remarks

Search criteria settings are retained throughout an application session. Use this method every time you change search criteria. This method will not reset the value of the LookIn property.


NewSearch Method Example

This example uses the NewSearch method to reset the default search criteria before beginning a new search.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .FileName = "run"
    .TextOrProperty = "San*"
    .MatchAllWordForms = True
    .FileType = msoFileTypeAllFiles
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
        " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


Open Method

Opens the specified HTML project or HTML project item in the Microsoft Script Editor in one of the views specified by the optional MsoHTMLProjectOpen constants (msoHTMLProjectOpenSourceView and msoHTMLProjectOpenTextView). If one of the constants is not specified, the project item is opened in the default view.

Syntax

expression.Open(OpenKind)

expression Required. An HTMLProject or HTMLProjectItem object.

OpenKind Optional Integer. The view in which the specified project or project item is opened.

Remarks

The default view is determined by whether or not the Microsoft Script Editor is open when the Open method is executed. If the Script Editor is not open, the Open method starts the Script Editor in source view. If the Script Editor is already open, the Open method activates the Script Editor and displays the script in the current view.


Open Method Example

This example opens the HTML project in the active workbook in source view.

AppActiveWorkbook.HTMLProject.Open _
    (msoHTMLProjectOpenSourceView)

This example opens the first HTML project item in the active workbook in text view.

ActiveWorkbook.HTMLProject.HTMLProjectItems _
    Item(1).Open (msoHTMLProjectOpenTextView)


 PasteFace Method

PasteFace Method

Pastes the contents of the Clipboard onto a command bar button control.

Syntax

expression.PasteFace

expression Required. An expression that returns a CommandBarButton object.


PasteFace Method Example

This example finds the built-in FileOpen button and pastes the face from the Spelling and Grammar button onto it from the Clipboard.

Set myControl = CommandBars.FindControl(Type:=msoControlButton, Id:=2)
myControl.CopyFace
Set myControl = CommandBars.FindControl(Type:=msoControlButton, Id:=23)
myControl.PasteFace


RefreshDocument Method

Refreshes the specified HTML project in the Microsoft Office host application.

Syntax

expression.RefreshDocument(Refresh)

expression An expression that returns an HTMLProject object.

Refresh Required Boolean. True is all changes are to be saved; False if all changes are to be ignored.

Remarks

Using this method is equivalent to clicking the Refresh button on the Refresh toolbar in the Office host application. If you refresh the document by setting the RefreshDocument method to True, all changes to the HTML source made in the Microsoft Script Editor are saved in the Office host application. If you set RefreshDocument to False, all changes to the HTML source are ignored. Note that the value returned by the State method is affected by the RefreshDocument method. If you call RefreshDocument (True), the State method returns msoHTMLProjectStateDocumentProjectUnlocked if it is called after the refresh operation.


RefreshDocument Method Example

This example refreshes the HTML project in the active workbook in the host application.

ActiveWorkbook.HTMLProject.RefreshDocument (True)


RefreshProject Method

Refreshes the specified HTML project in the Microsoft Script Editor.

Syntax

expression.RefreshProject

expression An expression that returns an HTMLProject object.

Remarks

Using this method is equivalent to clicking the Refresh button on the Refresh toolbar in the Microsoft Script Editor. If you refresh the document by setting RefreshDocument to True, all changes to the HTML source made in the Office host application are saved to the HTML project in the Microsoft Script Editor. If you set RefreshDocument to False, all changes to the HTML source are ignored.


RefreshProject Method Example

This example refreshes the HTML project in the Microsoft Script Editor.

ActiveWorkbook.HTMLProject.RefreshProject (True)


 ReleaseFocus Method

ReleaseFocus Method

Releases the user interface focus from all command bars.

Syntax

expression.ReleaseFocus

expression Required. An expression that returns a CommandBars object.


ReleaseFocus Method Example

This example adds three blank buttons to the command bar named “Custom” and sets the focus to the center button. The example then waits five seconds before releasing the user interface focus from all command bars.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlButton
    .Controls.Add Type:=msoControlButton
    .Controls.Add Type:=msoControlButton
    .Visible = True
End With
Set myControl = CommandBars("Custom").Controls(2)
With myControl
    .SetFocus
End With
PauseTime = 5   ' Set duration.
    Start = Timer   ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer
CommandBars.ReleaseFocus


Remove Method

Removes a PropertyTest object from the PropertyTests collection.

Syntax

expression.Remove(lndex)

expression Required. An expression that returns a PropertyTests object.

lndex Required Long. The index number of the property test to be removed.


 RemoveItem Method

RemoveItem Method

Removes an item from a command bar combo box control.

Note The property fails when applied to controls other than list controls.

Syntax

expression.RemoveItem(Index)

expression Required. An expression that returns a CommandBarComboBox object.

Index Required Long. The item to be removed from the list.


RemoveItem Method Example

This example determines whether there are more than three items in the specified combo box. If there are more than three items, the example removes the second item, alters the style, and sets a new value. It also sets the Tag property of the parent object (the CommandBarControl object) to show that the list has changed.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
With CommandBars("Custom").Controls(1)
    .AddItem "Get Stock Quote", 1
    .AddItem "View Chart", 2
    .AddItem "View Fundamentals", 3
    .AddItem "View News", 4
    .Caption = "Stock Data"
    .DescriptionText = "View Data For Stock"
End With
Set myControl = myBar.Controls(1)
With myControl
    If .ListCount > 3 Then
        .RemoveItem 2
        .Style = msoComboNormal
        .Text = "New Default"
         Set ctrl = .Parent
    End If
End With


 Reset Method

Reset Method

Resets a built-in command bar to its default configuration, or resets a built-in command bar control to its original function and face.

Syntax

expression.Reset

expression Required. An expression that returns a CommandBar, CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Remarks

Resetting a built-in control restores the actions originally intended for the control and resets each of the control's properties back to its original state. Resetting a built-in command bar removes custom controls and restores built-in controls.


ResetFileList Method

Resets the list of files for the current AnswerWizard to the default list of files for the Microsoft Office host application.

Syntax

expression.ResetFileList

expression An expression that returns an AnswerWizard object.

Remarks

Use this method to restore all entries in the current AnswerWizard file list to the list in the Windows registry for the host application. You can establish a custom default file list in the registry by adding the names of the custom files to the appropriate registry key. For more information about the registry and about using it to store AnswerWizard file name strings, see the Microsoft Office 2000 Resource Kit.


ResetFileList Method Example

This example resets the file list for the current AnswerWizard and then displays both the file count and the file names in a message box.

Dim customAnswerWizard As AnswerWizard
Dim strFileList As String
Dim intCounter As Integer
Dim intNumFiles As Integer

Set customAnswerWizard = Application.AnswerWizard
intCounter = 1

customAnswerWizard.ResetFileList
strFileList = ""
intNumFiles = customAnswerWizard.Files.Count
For intCounter = 1 To (intNumFiles)
    strFileList = strFileList & _
    customAnswerWizard.Files.Item(intCounter) & Chr(13)
Next

MsgBox "There are " & customAnswerWizard.Files.Count & _
    " files avaialble through this AnswerWizard: " & _
    Chr(13) & strFileList


ResetTips Method

Resets the application tips that appear in the Office Assistant balloon.

Syntax

expression.ResetTips

expression Required. An expression that returns an Assistant object.

Remarks

The ResetTips method corresponds to the Reset my tips button on the Options tab in the Office Assistant dialog box.


ResetTips Method Example

This example resets the application tips before making the Office Assistant visible. A confirmation balloon will appear, telling the user that his or her application tips have been reset.

With Application.Assistant
    .On = True
    .Visible = True
    .Animation = msoAnimationGreeting
    .ResetTips
End With


SaveCopyAs Method

Saves the specified HTML project item using a new file name.

Syntax

expression.SaveCopyAs(Filename)

expression An HTMLProjectItem object.

Filename Required String. The fully qualified path of the file to which you want to save the HTML project item.


SaveCopyAs Method Example

This example saves a copy of the text of the current HTML project item to the file NewScript.txt.

ActiveWorkbook.HTMLProject.HTMLProjectItems. _
    Item(1).SaveCopyAs("C:\NewScript.txt")


SetAvoidRectangle Method

Prevents the Office Assistant balloon from being displayed in a specified area of the screen.

Syntax

expression.SetAvoidRectangle(Left, Top, Right, Bottom)

expression Required. An expression that returns an Assistant object.

Left, Top, Right, Bottom Required Long. The coordinates (in points and relative to the screen) of the area of the screen that the Office Assistant balloon will avoid when it's displayed.

Remarks

This property is intended to prevent the Office Assistant balloon from overlapping custom dialog boxes and wizards.


SetAvoidRectangle Method Example

This example prevents the Office Assistant balloon represented by the variable myBalloon from being displayed in the region of the screen denoted by the specified coordinates.

Set myBalloon = Assistant.NewBalloon
With myBalloon
    .SetAvoidRectangle 300, 250, 700, 500
    .Text = "Cannot display in coordinates " & _
        "300, 250, 700, 500."
    .Show
End With


 SetFocus Method

SetFocus Method

Moves the keyboard focus to the specified command bar control. If the control is disabled or isn't visible, this method will fail.

Remarks

The focus on the control is subtle. After you use this method, you will notice a three dimensional highlight on the control. Pressing the arrow keys will navigate in the toolbars, as if you had arrived at the control by pressing only keyboard controls.

Syntax

expression.SetFocus

expression Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.


SetFocus Method Example

This example creates a command bar named "Custom" and adds a ComboBox control and a Button control to it. The example then uses the SetFocus method to set the focus to the ComboBox control.

Set focusBar = CommandBars.Add(Name:="Custom")
With CommandBars("Custom")
    .Visible = True
    .Position = msoBarTop
End With

Set testComboBox = CommandBars("Custom").Controls _
    .Add(Type:=msoControlComboBox, ID:=1)
With testComboBox
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
End With
Set testButton = CommandBars("Custom").Controls _
    .Add(Type:=msoControlButton)
testButton.FaceId = 17
' Set the focus to the combo box.
testComboBox.SetFocus


Show Method

Balloon object: Displays the specified balloon object. Returns an MsoBalloonType constant that indicates which button or label the user clicks. Read-only Long.

Syntax

expression.Show

expression Required. An expression that returns a Balloon object.

Remarks

You can use the return value of the Show method to display a user's button or BalloonLabel selection. The Show method returns one of the following MsoBalloonButtonType constants when the BalloonType property is set to msoBalloonTypeButtons:

msoBalloonButtonAbort

msoBalloonButtonCancel

msoBalloonButtonIgnore

msoBalloonButtonNo

msoBalloonButtonOK

msoBalloonButtonRetry

msoBalloonButtonSnooze

msoBalloonButtonYes

 msoBalloonButtonBack

msoBalloonButtonClose

msoBalloonButtonNext

msoBalloonButtonNull

msoBalloonButtonOptions

msoBalloonButtonSearch

msoBalloonButtonTips

msoBalloonButtonYesToAll


 ShowPopup Method

ShowPopup Method

Displays a command bar as a shortcut menu at the specified coordinates or at the current pointer coordinates.

Note If the Position property of the command bar is not set to msoBarPopup, this method fails.

Syntax

expression.ShowPopup(x, y)

expression Required. An expression that returns a CommandBar object.

x Optional Variant. The x-coordinate for the location of the shortcut menu. If this argument is omitted, the current x-coordinate of the pointer is used.

y Optional Variant. The y-coordinate for the location of the shortcut menu. If this argument is omitted, the current y-coordinate of the pointer is used.


ShowPopup Method Example

This example creates a shortcut menu containing two controls. The ShowPopup method is used to make the shortcut menu visible.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarPopup, Temporary:=False)
With myBar
    .Controls.Add Type:=msoControlButton, Id:=3
    .Controls.Add Type:=msoControlComboBox
End With
myBar.ShowPopup


StartWizard Method

Starts the Office Assistant and returns a Long value that identifies the session. You should use this method only to run the Office Assistant in a custom wizard.

Note The number returned by StartWizard method is used by the ActivateWizard and EndWizard methods.

Syntax

expression.StartWizard(On, Callback, PrivateX, Animation, CustomTeaser, Top, Left, Bottom, Right)

expression Required. An expression that returns an Assistant object.

On Required Boolean. True to display the Office decision balloon. The Office decision balloon asks the user whether he or she wants help with the active custom wizard. It isn't necessary to use the Visible property to display the Office Assistant if you specify True for this argument.

Callback Required String. The name of the callback procedure run by the Office decision balloon and the branch balloon. The branch balloon allows the user to choose between custom Help you've provided for the wizard and standard Office Help.

PrivateX Required Long. A number that identifies the balloon that initiated the callback procedure.

Animation Optional Variant. The animation the Office Assistant performs when this method is used. The default value is msoAnimationGetWizardy.

CustomTeaser Optional Variant. False to display the Office decision balloon.

Top, Left, Bottom, Right Optional Variant. The position of the corners (in points and relative to the screen) of the custom wizard form the Office Assistant will avoid when the Office Assistant appears.

Remarks

Unlike callback procedures used by standard modeless balloons, the callback procedure called by the modeless decision and branch balloons displayed during an Office Assistant wizard session takes only two arguments: an MsoWizardMsgType constant, and the unique value specified by the PrivateX argument of the StartWizard method.

If the user clicks the left button in the decision or branch balloon, the constant msoWizardMsgShowHelp is passed to the first argument of the callback procedure. If the user clicks the right button, the constant msoWizardLocalStateOff is passed. (The other MsoWizardMsgType constants are passed by the ActivateWizard method if you’ve specified msoWizardActResume or msoWizardActSuspend for the Act argument.) In the case of msoWizardMsgShowHelp, the callback procedure should display the appropriate balloon for the current panel of the custom wizard. And in the case of msoWizardLocalStateOff, the callback procedure should hide the visible balloon.


StartWizard Method Example

This example starts the Office Assistant as part of a process to provide information while a custom wizard is running. The variable lHelpForWiz is set to the return value of the StartWizard method, which is Long.

lHelpForWiz = Assistant.StartWizard(On:=True, _
    Callback:="myCallback", PrivateX:=23)


State Method

Returns the state of the specified HTML project. The returned state can be one of the following MsoHTMLProjectState constants: msoHTMLProjectStateDocumentLocked, msoHTMLProjectStateDocumentProjectUnlocked, or msoHTMLProjectStateProjectLocked. Read-only Long.

Remarks

The MsoHTMLProjectState constants correspond to the state of the Refresh toolbar in the Microsoft Office host application or the Microsoft Script Editor. A return value of msoHTMLProjectStateDocumentLocked indicates that the Refresh toolbar is displayed in the host application; a value of msoHTMLProjectStateProjectLocked indicates that this toolbar is displayed in the Microsoft Script Editor; a value of msoHTMLProjectStateDocumentProjectUnlocked indicates that the toolbar is not displayed at all.


State Method Example

This example displays a message box containing the MsoHTMLProjectState constant that indicates the current state of the HTML project in the active workbook.

Select Case ActiveWorkbook.HTMLProject.State
    Case 1
        MsgBox "The current state is " & _
        "msoHTMLProjectStateDocumentLocked"
    Case 2
        MsgBox "The current state is " & _
        "msoHTMLProjectStateProjectLocked"
    Case 3
        MsgBox "The current state is " & _
        "msoHTMLProjectStateDocumentProjectUnlocked"
End Select


Update Method

Updates the contents of the COMAddIns collection from the list of add-ins stored in the Windows registry.

Syntax

expression.Update

expression The COMAddIns collection.

Remarks

Before you can use a given COM add-in in a Microsoft Office application, that add-in must be registered in the Windows registry as a COM component with a corresponding Component Category ID.


Update Method Example

The following example updates the contents of the COMAddIns collection from the list of add-ins stored in the Windows registry.

Application.COMAddIns.Update


New Objects

Objects that were added to Visual Basic in Microsoft Office are listed in the following table.

Object | Description
AnswerWizard | Represents the Answer Wizard in a Microsoft Office application.
COMAddIn | Represents a COM add-in in a Microsoft Office host application.
HTMLProject | Represents a top-level project branch, as in the Project Explorer or the Microsoft Script Editor.
LanguageSettings | Returns information about the language settings in a Microsoft Office application.
Script | Represents a block of HTML script in a Microsoft Word document, on a Microsoft Excel spreadsheet, or on a Microsoft PowerPoint slide.
WebPageFont | Represents the default font used when documents are saved as Web pages for a particular character set.


AnswerWizard Object

AnswerWizard collection (AnswerWizardFiles object)

Represents the Answer Wizard in a Microsoft Office application. There’s only one Answer Wizard per application, and all changes to the AnswerWizard or the AnswerWizardFiles collection affect the active Office application immediately.

Using the AnswerWizard Object

Use the ClearFileList method to remove all entries from the list of files available to the current Answer Wizard. Using this method ensures that the default files available to the Office host application are no longer accessible through the Answer Wizard, such as when you’re replacing the Answer Wizard files with custom .AW files. The following example clears the file list for the default Answer Wizard and then adds two files to the custom Answer Wizard.

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

Use the ResetFileList method to restore the list of files for the current Answer Wizard to the default list of files for the Office host application. You can also establish a custom default file list in the Windows registry by adding the names of the custom files to the appropriate registry key; the files specified in that registry key will then be restored when ResetFileList is called. This example resets the file list for the current Answer Wizard.

customAnswerWizard.ResetFileList

Use the Files property to get the collection of Answer Wizard file references. The Files property returns a collection of strings that refer to .AW files. The following example returns the AnswerWizardFiles collection and displays the file count in a message box.

Dim customAnswerWizardFiles As AnswerWizardFiles
Set customAnswerWizardFiles = Application.AnswerWizard.Files

MsgBox customAnswerWizardFiles.Count


AnswerWizardFiles Collection Object

AnswerWizard collection (AnswerWizardFiles object)

A collection of references to Answer Wizard files. The AnswerWizardFiles collection contains all of the Answer Wizard files (with the file name extension .AW) available to the active Microsoft Office application.

Using the AnswerWizardFiles Collection

Use the Files property to get the collection of Answer Wizard file references. The Files property returns a collection of strings that refer to .AW files. The following example returns the AnswerWizardFiles collection and displays the file count in a message box.

Dim customAnswerWizardFiles As AnswerWizardFiles
Set customAnswerWizardFiles = Application.AnswerWizard.Files

MsgBox customAnswerWizardFiles.Count

Use the Add method to make additional files available to the current Answer Wizard. The following example adds the file Custom_1.aw to the list of Answer Wizard files in the active Office application.

Dim customAnswerWizard As AnswerWizard
Set customAnswerWizard = Application.AnswerWizard

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

Use the Item property to get the name of an existing Answer Wizard file reference. The following example displays a message box containing the name of the file referred to by Item(1).

MsgBox customAnswerWizard.Files.Item(1)


Assistant Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

Represents the Microsoft Office Assistant.

Using the Assistant Object

Use the Assistant property to return the Assistant object. There isn't a collection for the Assistant object; only one Assistant object can be active at a time. Use the Visible property to display the Assistant, and use the On property to enable the Assistant.

Remarks

The default Assistant is Rocky. To select a different Assistant programmatically, use the FileName property.

The following example displays and animates the Assistant.

With Assistant
    .Visible = True
    .Animation = msoAnimationGreeting
End With


Balloon Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

Represents the balloon where the Office Assistant displays information. A balloon can contain controls such as check boxes and labels.

Using the Balloon Object

Use the NewBalloon property to return a Balloon object. There isn't a collection for the Balloon object; only one balloon can be visible at a time. However, it's possible to define several balloons and display any one of them when needed. For more information, see "Defining and Reusing Balloons" later in this topic.

Use the Show method to make the specified balloon visible. Use the Callback property to run procedures based on selections from modeless balloons (balloons that remain visible while a user works in the application). Use the Close method to close modeless balloons.

The following example creates a balloon that contains tips for saving entered data.

With Assistant.NewBalloon
    .BalloonType = msoBalloonTypeBullets
    .Icon = msoIconTip
    .Button = msoButtonSetOk
    .Heading = "Tips for Saving Information."
    .Labels(1).Text = "Save your work often."
    .Labels(2).Text = "Install a surge protector."
    .Labels(3).Text = "Exit your application properly."
    .Show
End With

Defining and Reusing Balloons

You can reuse balloon objects you've already created by assigning the object to a variable and displaying the variable when you need it. This example defines balloon1 and balloon2 separately so that they can be reused.

Set balloon1 = Assistant.NewBalloon
balloon1.Heading = "First balloon"
Set balloon2 = Assistant.NewBalloon
balloon2.Heading = "Second balloon"
balloon1.Show
balloon2.Show
balloon1.Heading = "First balloon, new heading"
balloon1.Show

Alternatively, instead of using separate variables, you can place the balloon object into an array.


BalloonCheckBox Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

Represents a check box in the Office Assistant balloon. The BalloonCheckBox object is a member of the BalloonCheckBoxes collection.

Using the BalloonCheckBox Object

Use CheckBoxes(index), where index is a number from 1 through 5, to return a single BalloonCheckBox object. There can be up to five check boxes in one balloon; each check box appears when a value is assigned to its Text property.

The following example creates a balloon with a heading, text, and three region choices. The user selects one or more check boxes and clicks OK. The example calls the specified procedure or procedures.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select your region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    .Show
    If .CheckBoxes(1).Checked Then
        runregion1
    End If
    If .CheckBoxes(2).Checked Then
        runregion2
    End If
    If .CheckBoxes(3).Checked Then
        runregion3
    End If
End With

Remarks

Balloon check boxes display the user's choices until the user dismisses the balloon. You can use balloon labels to return a number corresponding to the user's choice in the Select method as soon as the user clicks the button beside the label. To pass values to the Select method based on the user's choice, you must have the balloon type set to msoBalloonTypeButtons.


BalloonCheckBoxes Collection Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

A collection of BalloonCheckBox objects that represent all the check boxes in the Office Assistant balloon.

Using the BalloonCheckBoxes Collection

Use the CheckBoxes property to return the BalloonCheckBoxes collection.

Use CheckBoxes(index), where index is a number from 1 through 5, to return a single BalloonCheckBox object. You can specify up to five check boxes (and five labels) per balloon; each check box appears when a value is assigned to its Text property. If you specify more than five check boxes, a run-time error occurs.

The following example creates a balloon with a heading, text, and three region choices. When the user selects one or more check boxes and then clicks OK, the specified procedure or procedures are called.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select your region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    .Show
    If .CheckBoxes(1).Checked Then
        runregion1
    End If
    If .CheckBoxes(2).Checked Then
        runregion2
    End If
    If .CheckBoxes(3).Checked Then
        runregion3
    End If
End With

You cannot add check boxes to or remove check boxes from the BalloonCheckBoxes collection after the balloon has been displayed.

Remarks

Balloon check boxes display the user's choices until the user dismisses the balloon. You can use balloon labels in conjunction with the Select method to return a number corresponding to the user's choice of check boxes as soon as the user clicks the button beside the label. To pass values to the Select method based on the user's choice, you must have the balloon type set to msoBalloonTypeButtons.


BalloonLabel Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

Represents a label in the Office Assistant balloon. The BalloonLabel object is a member of the BalloonLabels collection.

Using the BalloonLabel Object

Use Labels(index), where index is a number from 1 through 5, to return a BalloonLabel object. There can be up to five labels on one balloon; each label appears when a value is assisgned to its Text property.

The following example creates a balloon that asks the user to click the label corresponding to his or her age.

With Assistant.NewBalloon
    .Heading = "Check Your Age Group."
    .Labels(1).Text = "Under 30."
    .Labels(2).Text = "30 to 50."
    .Labels(3).Text = "Over 50."
    .Text = "Which of the following " _
        & .Labels.Count & " choices apply to you?"
    .Show
End With

Remarks

Balloon check boxes display the user's choices until he or she dismisses the balloon. You can use balloon labels to return a number corresponding to the user's choice in the Select method as soon as the user clicks the button beside the label. To pass values to the Select method based on the user's choice, you must have the balloon type be set to msoBalloonTypeButtons.


BalloonLabels Collection Object

BalloonCheckBoxes collection (BalloonCheckBox object)
BalloonLabels collection (BalloonLabel object)

A collection of BalloonLabel objects that represent all the labels in the Office Assistant balloon.

Using the BalloonLabels Collection

Use the Labels property to return the BalloonLabels collection.

Use Labels(index), where index is a number from 1 through 5, to return a BalloonLabel object. You can specify up to five labels (and five check boxes) per balloon; each label appears when a value is assisgned to its Text property. If you specify more than five labels, a run-time error occurs.

The following example creates a balloon containing three choices. The variable returnValue is set to the return value of the Show method, which will be 1, 2, or 3, corresponding to the label the user clicks. The example returns the value of the variable returnValue, which you can either pass to another procedure or use in a Select Case statement.

Set b = Assistant.NewBalloon
With b
    .Heading = "This is my heading"
    .Text = "Select one of these things:"
    .Labels(1).Text = "Choice One"
    .Labels(2).Text = "Choice Two"
    .Labels(3).Text = "Choice Three"
    returnValue = .Show
End With

Remarks

Balloon check boxes display the user's choices until the user dismisses the balloon. You can use balloon labels to return a number corresponding to the user's choice in the Select method as soon as the user clicks the button beside the label. To pass values to the Select method based on the user's choice, you must have the balloon type set to msoBalloonTypeButtons.


COMAddIn Object

COMAddIns collection (COMAddIn) object

Represents a COM add-in in the Microsoft Office host application. The COMAddIn object is a member of the COMAddIns collection.

Using the COMAddIn Object

Use COMAddIns.Item(index), where index is either an ordinal value that returns the COM add-in at that position in the COMAddIns collection, or a String value that represents the ProgID of the specified COM add-in. The following example displays a COM add-in’s description text in a message box.

MsgBox Application.COMAddIns.Item("msodraa9.ShapeSelect").Description

Use the ProgID property of the COMAddin object to return the programmatic identifier for a COM add-in, and use the Guid property to return the globally unique identifier (GUID) for the add-in. The following example displays the ProgID and GUID for COM add-in one in a message box.

MsgBox "My ProgID is " & _
    Application.COMAddIns(1).ProgID & _
    " and my GUID is " & _
    Application.COMAddIns(1).Guid

Use the Connect property to set or return the state of the connection to a specified COM add-in. The following example displays a message box that indicates whether COM add-in one is registered and currently connected.

If Application.COMAddIns(1).Connect Then
    MsgBox "The add-in is connected."
Else
MsgBox "The add-in is not connected."
End If

For a detailed description of how to develop a COM add-in, see the chapter "Add-ins, Templates, Wizards, and Libraries" in the Microsoft Office 2000/Visual Basic Programmer's Guide.


COMAddIns Collection Object

COMAddIns collection (COMAddIn) object

A collection of COMAddIn objects that provide information about a COM add-in registered in the Windows registry.

Using the COMAddIns Collection

Use the COMAddIns property of the Application object to return the COMAddIns collection for a Microsoft Office host application. This collection contains all of the COM add-ins that are available to a given Office host application, and the Count property of the COMAddins collection returns the number of available COM add-ins, as in the following example.

MsgBox Application.COMAddIns.Count

Use the Update method of the COMAddins collection to refresh the list of COM add-ins from the Windows registry, as in the following example.

Application.COMAddIns.Update

Use COMAddIns.Item(index), where index is either an ordinal value that returns the COM add-in at that position in the COMAddIns collection, or a String value that represents the ProgID of the specified COM add-in. The following example displays a COM add-in’s description text and ProgID ("msodraa9.ShapeSelect") in a message box.

MsgBox Application.COMAddIns.Item("msodraa9.ShapeSelect").Description

For a detailed description of how to develop a COM add-in, see the chapter "Add-ins, Templates, Wizards, and Libraries" in the Microsoft Office 2000/Visual Basic Programmer's Guide.


 CommandBar Object

CommandBar Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

Represents a command bar in the container application. The CommandBar object is a member of the CommandBars collection.

Using the CommandBar Object

Use CommandBars(index), where index is the name or index number of a command bar, to return a single CommandBar object. The following example steps through the collection of command bars to find the command bar named "Forms." If it finds this command bar, the example makes it visible and protects its docking state. In this example, the variable cb represents a CommandBar object.

foundFlag = False
For Each cb In CommandBars
    If cb.Name = "Forms" Then
        cb.Protection = msoBarNoChangeDock
        cb.Visible = True
        foundFlag = True
    End If
Next cb
If Not foundFlag Then
    MsgBox "The collection does not contain a Forms command bar."
End If

You can use a name or index number to specify a menu bar or toolbar in the list of available menu bars and toolbars in the container application. However, you must use a name to specify a menu, shortcut menu, or submenu (all of which are represented by CommandBar objects). This example adds a new menu item to the bottom of the Tools menu. When clicked, the new menu item runs the procedure named "qtrReport."

Set newItem = CommandBars("Tools").Controls.Add(Type:=msoControlButton)
With newItem
    .BeginGroup = True
    .Caption = "Make Report"
    .FaceID = 0
    .OnAction = "qtrReport"
End With

If two or more custom menus or submenus have the same name, CommandBars(index) returns the first one. To ensure that you return the correct menu or submenu, locate the pop-up control that displays that menu. Then apply the CommandBar property to the pop-up control to return the command bar that represents that menu.

Assuming that the third control on the toolbar named "Custom Tools" is a pop-up control, this example adds the Save command to the bottom of that menu.

Set viewMenu = CommandBars("Custom Tools").Controls(3)
viewMenu.Controls.Add ID:=3    'ID of Save command is 3


 CommandBars Collection Object

CommandBars Collection Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

A collection of CommandBar objects that represent the command bars in the container application.

Using the CommandBars Collection

Use the CommandBars property to return the CommandBars collection. The following example displays in the Immediate window both the name and local name of each menu bar and toolbar, and it displays a value that indicates whether the menu bar or toolbar is visible.

For Each cbar in CommandBars
    Debug.Print cbar.Name, cbar.NameLocal, cbar.Visible
Next

Use the Add method to add a new command bar to the collection. The following example creates a custom toolbar named "Custom1" and displays it as a floating toolbar.

Set cbar1 = CommandBars.Add(Name:="Custom1", Position:=msoBarFloating)
cbar1.Visible = True

Use CommandBars(index), where index is the name or index number of a command bar, to return a single CommandBar object. The following example docks the toolbar named "Custom1" at the bottom of the application window.

CommandBars("Custom1").Position = msoBarBottom

Note You can use the name or index number to specify a menu bar or toolbar in the list of available menu bars and toolbars in the container application. However, you must use the name to specify a menu, shortcut menu, or submenu (all of which are represented by CommandBar objects).

If two or more custom menus or submenus have the same name, CommandBars(index) returns the first one. To ensure that you return the correct menu or submenu, locate the pop-up control that displays that menu. Then apply the CommandBar property to the pop-up control to return the command bar that represents that menu.


 CommandBarButton Object

CommandBarButton Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

Represents a button control on a command bar.

Using the CommandBarButton Object

Use Controls(index), where index is the index number of the control, to return a CommandBarButton object. (The Type property of the control must be msoControlButton.)

Assuming that the second control on the command bar named "Custom" is a button, the following example changes the style of that button.

Set c = CommandBars("Custom").Controls(2)
With c
If .Type = msoControlButton Then
    If .Style = msoButtonIcon Then
        .Style = msoButtonIconAndCaption
    Else
        .Style = msoButtonIcon
    End If
End If
End With

You can also use the FindControl method to return a CommandBarButton object.


 CommandBarComboBox Object

CommandBarComboBox Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

Represents a combo box control on a command bar.

Using the CommandBarComboBox Object

Use Controls(index), where index is the index number of the control, to return a CommandBarComboBox object. (The Type property of the control must be msoControlEdit, msoControlDropdown, msoControlComboBox, msoControlButtonDropdown, msoControlSplitDropdown, msoControlOCXDropdown, msoControlGraphicCombo, or msoControlGraphicDropdown.)

The following example adds two items to the second control on the command bar named "Custom," and then it adjusts the size of the control.

Set combo = CommandBars("Custom").Controls(2)
With combo
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListIndex = 0
End With

You can also use the FindControl method to return a CommandBarComboBox object. The following example searches all command bars for a visible CommandBarComboBox object whose tag is "sheet assignments."

Set myControl = CommandBars.FindControl _
(Type:=msoControlComboBox, Tag:="sheet assignments", Visible:=True)


 CommandBarControl Object

CommandBarControl Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

Represents a command bar control. The CommandBarControl object is a member of the CommandBarControls collection. The properties and methods of the CommandBarControl object are all shared by the CommandBarButton, CommandBarComboBox, and CommandBarPopup objects.

Note When writing Visual Basic code to work with custom command bar controls, you use the CommandBarButton, CommandBarComboBox, and CommandBarPopup objects. When writing code to work with built-in controls in the container application that cannot be represented by one of those three objects, you use the CommandBarControl object.

Using the CommandBarControl Object

Use Controls(index), where index is the index number of a control, to return a CommandBarControl object. (The Type property of the control must be msoControlLabel, msoControlExpandingGrid, msoControlSplitExpandingGrid, msoControlGrid, or msoControlGauge.)

Note Variables declared as CommandBarControl can be assigned CommandBarButton, CommandBarComboBox, and CommandBarPopup values.

You can also use the FindControl method to return a CommandBarControl object. The following example searches for a control of type msoControlGauge; if it finds one, it displays the index number of the control and the name of the command bar that contains it. In this example, the variable lbl represents a CommandBarControl object.

Set lbl = CommandBars.FindControl(Type:= msoControlGauge)
If lbl Is Nothing Then
    MsgBox "A control of type msoControlGauge was not found."
Else
    MsgBox "Control " & lbl.Index & " on command bar " _
        & lbl.Parent.Name & " is type msoControlGauge"
End If


 CommandBarControls Collection Object

CommandBarControls Collection Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

A collection of CommandBarControl objects that represent the command bar controls on a command bar.

Using the CommandBarControls Collection

Use the Controls property to return the CommandBarControls collection. The following example changes the caption of every control on the toolbar named "Standard" to the current value of the Id property for that control.

For Each ctl In CommandBars("Standard").Controls
    ctl.Caption = CStr(ctl.Id)
Next ctl

Use the Add method to add a new command bar control to the CommandBarControls collection. This example adds a new, blank button to the command bar named "Custom."

Set myBlankBtn = CommandBars("Custom").Controls.Add

Use Controls(index), where index is the caption or index number of a control, to return a CommandBarControl, CommandBarButton, CommandBarComboBox, or CommandBarPopup object. The following example copies the first control from the command bar named "Standard" to the command bar named "Custom."

Set myCustomBar = CommandBars("Custom")
Set myControl = CommandBars("Standard").Controls(1)
myControl.Copy Bar:=myCustomBar, Before:=1


 CommandBarPopup Object

CommandBarPopup Object

CommandBars collection (CommandBar object)
CommandBarControls collection (CommandBarControl object)

Represents a pop-up control on a command bar.

Using the CommandBarPopup Object

Use Controls(index), where index is the number of the control, to return a CommandBarPopup object. (The Type property of the control must be msoControlPopup, msoControlGraphicPopup, msoControlButtonPopup, msoControlSplitButtonPopup, or msoControlSplitButtonMRUPopup.)

You can also use the FindControl method to return a CommandBarPopup object. The following example searches all command bars for a CommandBarPopup object whose tag is "Graphics."

Set myControl = Application.CommandBars.FindControl _
(Type:=msoControlPopup, Tag:="Graphics")

Remarks

Every pop-up control contains a CommandBar object. To return the command bar from a pop-up control, apply the CommandBar property to the CommandBarPopup object.


DocumentProperty Object

Represents a custom or built-in document property of a container document. The DocumentProperty object is a member of the DocumentProperties collection.

Using the DocumentProperty Object

Use BuiltinDocumentProperties(index), where index is the name or index number of the built-in document property, to return a single DocumentProperty object that represents a specific built-in document property. Use CustomDocumentProperties(index), where index is the name or index number of the custom document property, to return a DocumentProperty object that represents a specific custom document property.

The following list contains the names of all the available built-in document properties:

Title

Subject

Author

Keywords

Comments

Template

Last Author

Revision Number

Application Name

Last Print Date

Creation Date

Last Save Time

Total Editing Time

Number of Pages

 Number of Words

Number of Characters

Security

Category

Format

Manager

Company

Number of Bytes

Number of Lines

Number of Paragraphs

Number of Slides

Number of Notes

Number of Hidden Slides

Number of Multimedia Clips

Container applications don't necessarily define a value for every built-in document property. If a given application doesn't define a value for one of the built-in document properties, returning the Value property for that document property causes an error.


DocumentProperties Collection Object

A collection of DocumentProperty objects. Each DocumentProperty object represents a built-in or custom property of a container document.

Using the DocumentProperties Collection

Use the Add method to create a new custom property and add it to the DocumentProperties collection. You cannot use the Add method to create a built-in document property.

Use BuiltinDocumentProperties(index), where index is the index number of the built-in document property, to return a single DocumentProperty object that represents a specific built-in document property. Use CustomDocumentProperties(index), where index is the number of the custom document property, to return a DocumentProperty object that represents a specific custom document property.


FileSearch Object

PropertyTests collection (PropertyTest object)

Represents the functionality of the Open dialog box (File menu).

Using the FileSearch Object

Use the FileSearch property to return the FileSearch object. The following example searches for files and displays the number of files found and the name of each file.

With Application.FileSearch
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With

Use the NewSearch method to reset the search criteria to the default settings. All property values are retained after each search is run, and by using the NewSearch method you can selectively set properties for the next file search without manually resetting previous property values. The following example resets the search criteria to the default settings before beginning a new search.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .FileName = "Run"
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
End With


FoundFiles Object

PropertyTests collection (PropertyTest object)

Represents the list of files returned from a file search.

Using the FoundFiles Object

Use the FoundFiles property to return the FoundFiles object. This example steps through the list of files that are found and displays the path and file name of each file. Use FoundFiles(index), where index is the index number, to return the path and file name of a specific file found during the search.

With Application.FileSearch
    For i = 1 To .FoundFiles.Count
        MsgBox .FoundFiles(i)
    Next I
End With

Use the Execute method to begin the file search and update the FoundFiles object. The following example searches the My Documents folder for all files whose names begin with "Cmd" and displays the name and location of each file that's found. The example also sorts the returned files in ascending alphabetic order by file name.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "cmd*"
    If .Execute(SortBy:=msoSortbyFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


HTMLProject Object

HTMLProjectItems collection (HTMLProjectItem) object

Represents a top-level project branch, as in the Project Explorer in the Microsoft Script Editor.

Using the HTMLProject Object

Use the Open method of the HTMLProject object to open an HTML project in the Microsoft Script Editor. The project is opened in source view or text view for the active Microsoft Word document, Excel workbook, or PowerPoint presentation. The following example opens an HTML project in the active Word document in source view.

ActiveDocument.HTMLProject.Open (msoHTMLProjectOpenSourceView)

Use the HTMLProjectItems property to return the collection of HTMLProjectItem objects in the HTML project. Use the RefreshDocument method to refresh the HTML document in the host application. Use the RefreshProject method to refresh the project in the Microsoft Script Editor. Use the State method to determine whether the HTML project needs to be refreshed.


HTMLProjectItem Object

HTMLProjectItems collection (HTMLProjectItem) object

Represents an individual project item that’s a project item branch in the Project Explorer in the Microsoft Script Editor. The HTMLProjectItem object is a member of the HTMLProjectItems collection.

Using the HTMLProjectItem Object

Use HTMLProjectItems(index), where index is the name or index number of a project item, to return a single HTMLProjectItem object. Use the Name property to return the display name of the project item. The following example returns the name of the first project item in the HTMLProjectItems collection for the active document.

MsgBox "The first item is " & _
    ActiveDocument.HTMLProject.HTMLProjectItems(1).Name

Use the Open method to open a project item in source view or text view, and use the IsOpen property to determine whether the project item is currently open. The following example opens the project item named “ItemOne” (in the active document) in the default view and then displays a message box stating whether the item was opened successfully.

ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne").Open
If ActiveDocument.HTMLProject. _
        HTMLProjectItems("ItemOne").IsOpen Then
MsgBox "Opened project item " & ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne").Name
End If

Use the SaveCopyAs method to save the project item using a new file name. The following example saves a copy of ItemOne as “NewItem”.

ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne") _
    .Open (msoHTMLProjectOpenTextView)
ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne") _
    .SaveCopyAs("C:\NewItem.txt")

Assuming that the text file C:\NewText.txt exists, the following example uses the LoadFromFile property to set the text of ItemOne to the text contained in the file. The following example uses the Text property to display the new text in a message box.

MsgBox ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").Text
ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").LoadFromFile("C:\NewText.txt")
MsgBox ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").Text


HTMLProjectItems Collection Object

HTMLProjectItems collection (HTMLProjectItem) object

A collection of HTMLProjectItem objects that represent the HTML project items contained in the HTMLProject object.

Using the HTMLProjectItems Collection

Use the HTMLProjectItems property of the HTMLProject object to return the HTMLProjectItems collection. Use the Count property of the HTMLProjectItems collection to return the number of project items in the HTML project for the specified document. Use the Item method of the HTMLProjectItems collection to return an individual project item. The following example returns the name of the first project item in the HTMLProjectItems collection for the active document.

MsgBox "The first item is " & _
    ActiveDocument.HTMLProject.HTMLProjectItems(1).Name


LanguageSettings Object

LanguageSettings object

Returns information about the language settings in a Microsoft Office application.

Using the LanguageSettings Object

Use Application.LanguageSettings.LanguageID(MsoAppLanguageID), where MsoAppLanguageID is one of the following constants used to return locale identifier (LCID) information to the specified application: msoLanguageIDExeMode, msoLanguageIDHelp, msoLanguageIDInstall, msoLanguageIDUI, or msoLanguageIDUIPrevious. The following example returns the install language, user interface language, and Help language LCIDs in a message box.

MsgBox "The following locale IDs are registered " & _
    "for this application: Install Language - " & _
    Application.LanguageSettings.LanguageID(msoLanguageIDInstall) & _
    " User Interface Language - " & _
    Application.LanguageSettings.LanguageID(msoLanguageIDUI) & _
    " Help Language - " & _
    Application.LanguageSettings.LanguageID(msoLanguageIDHelp)

Use Application.LanguageSettings.LanguagePreferredForEditing to determine which LCIDs are registered as preferred editing languages for the application, as in the following example.

If Application.LanguageSettings. _
    LanguagePreferredForEditing(msoLanguageIDEnglishUS) Then
    MsgBox "U.S. English is one of the chosen editing languagess."
End If


PropertyTest Object

PropertyTests collection (PropertyTest object)

Represents a single file search criterion. Search criteria are listed in the Advanced Find dialog box (File menu, Open command, Advanced Find button). The PropertyTest object is a member of the PropertyTests collection.

Using the PropertyTest Object

Use PropertyTests(index), where index is the index number, to return a single PropertyTest object. The following example displays all the search criteria for the first property test in the PropertyTests collection.

With Application.FileSearch.PropertyTests(1)
myString = "This is the search criteria: " _
    & " The name is: " & .Name & ". The condition is: " _
    & .Condition
If .Value <> "" Then
    myString = myString & ". The value is: " & .Value
    If .SecondValue <> "" Then
        myString = myString _
            & ". The second value is: " _
            & .SecondValue & ", and the connector is" _
            & .Connector
    End If
End If
MsgBox myString
End With


PropertyTests Collection Object

PropertyTests collection (PropertyTest object)

A collection of PropertyTest objects that represent all the search criteria of a file search. Search criteria are listed in the Advanced Find dialog box (File menu, Open command, Advanced Find button).

Using the PropertyTests Collection

Use the PropertyTests property to return the PropertyTests collection. The following example displays the number of advanced-find search criteria that will be used for one file search.

Application.FileSearch.PropertyTests.Count

Use the Add method to add a new PropertyTest object to the PropertyTests collection. The following example adds two property tests to the search criteria. The first criterion specifies that the files that are found can be of any file type, and the second criterion specifies that these files must have been modified between January 1, 1996, and June 30, 1996. The example displays the number of files found and displays the name of each file in a message box.

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

Use PropertyTests(index), where index is the index number, to return a single PropertyTest object. The following example displays all the search criteria for the first property test in the PropertyTests collection.

With Application.FileSearch.PropertyTests(1)
myString = "This is the search criteria: " _
    & " The name is: " & .Name & ". The condition is: " _
    & .Condition
If .Value <> "" Then
    myString = myString & ". The value is: " & .Value
    If .SecondValue <> "" Then
        myString = myString _
            & ". The second value is: " _
            & .SecondValue & ", and the connector is" _
            & .Connector
    End If
End If
MsgBox myString
End With


Script Object

Scripts collection (Script) object

Represents a block of HTML script in a Microsoft Word document, on a Microsoft Excel spreadsheet, or on a Microsoft PowerPoint slide. The Script object is a member of the Scripts collection.

Using the Script Object

Use Scripts.Item(index), where index is the name, ID, or index number of a script, to return a single Script object. Each Script object is identified by the Id property, which provides a convenient name you can use to access the script. The following example adds a single script to the Scripts collection for the active document and displays the ID of the script at index value 1.

myScript = ActiveDocument.Scripts.Add( _
    , msoScriptLocationInBody, _
    msoScriptLanguageVisualBasic, _
    "ScriptOne", , _
    "MsgBox (""This is ScriptOne. "")")
MsgBox (ActiveDocument.Scripts(1).Id)

You can specify the scripting language used in the script by changing the Language property. The following example changes the scripting language of script one to Active Server Pages (ASP).

ActiveDocument.Scripts.Item("ScriptOne") _
    .Language = msoScriptLanguageASP

You can check the location of the script anchor shape within an HTML document by using the Location property. The following example checks to determine whether ScriptOne is in the body of the active HTML document.

If ActiveDocument.Scripts("ScriptOne").Location = _
    msoScriptLocationInBody Then
    MsgBox ("Script is in the HTML document body.")
Else
    MsgBox ("Script is located in the header. ")
End If

You can check or set attributes added to the <SCRIPT> tag (with the exception of the LANGUAGE and ID attributes) by using the Extended property. The following example checks for additional attributes in script one in the active document.

If ActiveDocument.Scripts(1).Extended = "" Then
    MsgBox ("No additional attributes are present " & _
    "in Script " &
     ActiveDocument.Scripts(1).Id)

You can check or set the script text associated with a given script by using the ScriptText property. The following example displays a message box containing the script text associated with script one in the active document.

MsgBox (ActiveDocument.Scripts("ScriptOne").ScriptText)


Scripts Collection Object

Scripts collection (Script) object

A collection of Script objects that represent the collection of HTML scripts in the specified document.

Using the Scripts Collection

The Scripts collection contains all of the Script objects in a given document, in source order (the order in which Script objects were added to the source file). Source order isn’t affected by the location (header or body text) of the script in the document. You can use Script objects to access a script or to add a script to a Microsoft Word document, a Microsoft Excel worksheet, or a Microsoft PowerPoint slide. You can also use the Scripts collection to access any HTML page or script that’s opened in a Microsoft Office application.

Note Microsoft Access doesn’t use this shared Office component.

Adding a Script

When you add a Script object to the Scripts collection, a Shape object of type msoScriptAnchor is automatically added to the document. On an Excel worksheet or a PowerPoint slide, the shape is added to the Shapes collection; in a Word Document, the shape is added to the InlineShapes collection. You add a Script to a document by using the Add method. The following example adds a simple script to the active Word document.

myScript = ActiveDocument.Scripts.Add( _
    , msoScriptLocationInBody, _
    msoScriptLanguageVisualBasic, _
    "ScriptOne", , _
    "MsgBox ""This is ScriptOne.""")

To access a particular item in the Scripts collection, use the Item method, and supply either the ID attribute of the <SCRIPT> tag or the index number that indicates the position of the script in the collection. The ID must be unique within the document. In the case of duplicate ID attributes, the first script found that has that ID is returned. The following example displays a message box indicating the language of the first script found that uses the ID "ScriptOne".

MsgBox (ActiveDocument.Scripts.Item("ScriptOne").Language)

Use the Count property to determine the number of Script objects in the specified document. The following example displays the number of scripts in the active document.

If ActiveDocument.Scripts.Count = 0 Then
    MsgBox ("There are no " & _
    "scripts in this document. ")
End If
If ActiveDocument.Scripts.Count = 1 Then
    MsgBox ("There is " & _
    ActiveDocument.Scripts.Count & _
    " script in this document. ")
End If
If ActiveDocument.Scripts.Count > 1 Then
    MsgBox ("There are " & _
    ActiveDocument.Scripts.Count & _
    " scripts in this document. ")
End If

Use the Delete method to remove a script from the Scripts collection, as in the following example.

ActiveDocument.Scripts("ScriptOne").Delete


WebPageFont Object

WebPageFonts collection (WebPageFont)

Represents the default font used when documents are saved as Web pages for a particular character set.

Using the WebPageFont Object

Use the WebPageFont object to describe the proportional font, proportional font size, fixed-width font, and fixed-width font size for any available character set. The following character sets are supported:

msoCharacterSetArabic
msoCharacterSetCyrillic
msoCharacterSetEnglishWesternEuropeanOtherLatinScript
msoCharacterSetGreek
msoCharacterSetHebrew
msoCharacterSetJapanese
msoCharacterSetKorean
msoCharacterSetMultilingualUnicode
msoCharacterSetSimplifiedChinese
msoCharacterSetThai
msoCharacterSetTraditionalChinese
msoCharacterSetVietnamese

The following example sets the proportional font and proportional font size for the WebPageFont object myFont.

With myFont
    ProportionalFont = Verdana
    ProportionalFontSize = 14


WebPageFonts Collection Object

WebPageFonts collection (WebPageFont)

A collection of WebPageFont objects that describe the proportional font, proportional font size, fixed-width font, and fixed-width font size used when documents are saved as Web pages. You can specify a different set of Web page font properties for each available character set.

Using the WebPageFonts Collection

The WebPageFonts collection contains one WebPageFont object for each of the following MsoCharacterSet constants:

msoCharacterSetArabic
msoCharacterSetCyrillic
msoCharacterSetEnglishWesternEuropeanOtherLatinScript
msoCharacterSetGreek
msoCharacterSetHebrew
msoCharacterSetJapanese
msoCharacterSetKorean
msoCharacterSetMultilingualUnicode
msoCharacterSetSimplifiedChinese
msoCharacterSetThai
msoCharacterSetTraditionalChinese
msoCharacterSetVietnamese

The following example uses the Item property to set myFont to the WebPageFont object for the English/Western European/Other Latin Script character set in the current application.

Dim myFont As WebPageFont
Set myFont = _
  Application.DefaultWebOptions.Fonts.Item_
  (msoCharacterSetEnglishWesternEuropeanOtherLatinScript)


New Properties (by Object)

Properties that have been added to existing objects in Microsoft Office are listed in the following table (sorted by object name).

Object | Property
Assistant | On
CommandBar | AdaptiveMenu
CommandBarButton | HyperlinkType
CommandBarButton | IsPriorityDropped
CommandBarComboBox | IsPriorityDropped
CommandBarControl | IsPriorityDropped
CommandBarPopup | IsPriorityDropped
CommandBars | AdaptiveMenus
CommandBars | DisplayFonts


ActionControl Property

Returns the CommandBarControl object whose OnAction property is set to the running procedure. If the running procedure was not initiated by a command bar control, this property returns Nothing. Read-only.


ActionControl Property Example

This example creates a command bar named “Custom”, adds three buttons to it, and then uses the ActionControl property and the Tag property to determine which command bar button was last clicked.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
Set buttonOne = myBar.Controls.Add(Type:=msoControlButton)
With buttonOne
    .FaceId = 133
    .Tag = "RightArrow"
    .OnAction = "whichButton"
End With
Set buttonTwo = myBar.Controls.Add(Type:=msoControlButton)
With buttonTwo
    .FaceId = 134
    .Tag = "UpArrow"
    .OnAction = "whichButton"
End With
Set buttonThree = myBar.Controls.Add(Type:=msoControlButton)
With buttonThree
    .FaceId = 135
    .Tag = "DownArrow"
    .OnAction = "whichButton"
End With
myBar.Visible = True

The whichButton subroutine responds to the OnAction method and determines which command bar button was last clicked.

Sub whichButton()
Select Case CommandBars.ActionControl.Tag
    Case "RightArrow"
        MsgBox ("Right Arrow button clicked.")
    Case "UpArrow"
        MsgBox ("Up Arrow button clicked.")
    Case "DownArrow"
        MsgBox ("Down Arrow button clicked.")
End Select
End Sub


ActiveMenuBar Property

Returns a CommandBar object that represents the active menu bar in the container application. Read-only.


ActiveMenuBar Property Example

This example adds a temporary pop-up control named "Custom" to the end of the active menu bar, and adds a control named "Import" to the pop-up control.

Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, Temporary:=True)
newMenu.Caption = "Custom"
Set ctrl1 = newMenu.CommandBar.Controls _
    .Add(Type:=msoControlButton, Id:=1)
With ctrl1
    .Caption = "Import"
    .TooltipText = "Import"
    .Style = msoButtonCaption
End With


AdaptiveMenu Property

True if a personalized menu is enabled. Read/write Boolean.


AdaptiveMenus Property

True if adaptive menus are enabled. Read/write Boolean.


AdaptiveMenus Property Example

This example sets three options for all command bars in Microsoft Office, including custom command bars and the controls on them.

With CommandBars
    .LargeButtons = True
    .DisplayFonts = True
    .AdaptiveMenus = True
End With


Animation Property

Returns or sets an animation action for the Office Assistant. When this property is applied to the Assistant object and the Assistant supports the specified animation, the Assistant is animated immediately (if the Assistant is visible and enabled). When this property is applied to the Balloon object, the Assistant is animated only while the balloon is displayed. Read/write Long.

Can be one of the following MsoAnimationType constants:

msoAnimationAppear

msoAnimationBeginSpeaking

msoAnimationCharacterSuccessMajor

msoAnimationCheckingSomething

msoAnimationDisappear

msoAnimationEmptyTrash

msoAnimationGestureDown

msoAnimationGestureLeft

msoAnimationGestureRight

msoAnimationGestureUp

msoAnimationGetArtsy

msoAnimationGetAttentionMajor

msoAnimationGetAttentionMinor

msoAnimationGetTechy

msoAnimationGetWizardy

msoAnimationGoodbye

msoAnimationGreeting

msoAnimationIdle

 msoAnimationListensToComputer

msoAnimationLookDown

msoAnimationLookDownLeft

msoAnimationLookDownRight

msoAnimationLookLeft

msoAnimationLookRight

msoAnimationLookUp

msoAnimationLookUpLeft

msoAnimationLookUpRight

msoAnimationPrinting

msoAnimationRestPose

msoAnimationSaving

msoAnimationSearching

msoAnimationSendingMail

msoAnimationThinking

msoAnimationWorkingAtSomething

msoAnimationWritingNotingSomething

Remarks

“Clippit” is the default Assistant, and msoAnimationIdle is the default animation type for the Assistant.

Depending on the selected Assistant, setting the Animation property may or may not result in an obvious animation. However, all MsoAnimationType constants are valid for all Assistants. Note that different constants may produce the same animation.

The following MsoAnimationType constants represent animations that repeat the specified action until the Assistant is dismissed or until the Animation property is reset with another animation:

msoAnimationCheckingSomething

msoAnimationGetTechy

msoAnimationListensToComputer

msoAnimationSearching

 msoAnimationThinking

msoAnimationWorkingAtSomething

msoAnimationWritingNotingSomething


Animation Property Example

This example displays the Office Assistant in a specific location and it sets several options before making the Assistant visible.

With Assistant
    .On = True
    .Visible = True
    .Move xLeft:= 400, yTop:= 300
    .MoveWhenInTheWay = True
    .TipOfDay = True
    .Animation = msoAnimationGreeting
End With


Application Property

Returns an Application object that represents the container application for the object (you can use this property with an Automation object to return that object's container application). Read-only Object.


Application Property Example

This example returns the name of the application in which the command bar named "Documents" was created and displays this result in a message box.

Set Appobj = CommandBars("Standard").Application
MsgBox Appobj


AssistWithAlerts Property

True if the Office Assistant balloon delivers application alerts when the Office Assistant is visible. Read/write Boolean.

Remarks

The AssistWithAlerts property corresponds to the Display alerts option under Use the Office Assistant on the Options tab in the Office Assistant dialog box.

If this property is set to False, the application displays alerts in dialog boxes.


AssistWithAlerts Property Example

This example sets the Office Assistant to be displayed whenever an application alert is generated.

With Assistant
    .On = True
    .Visible = True
    .AssistWithHelp = True
    .AssistWithAlerts = True
    .Animation = msoAnimationGetAttentionMajor
End With


AssistWithHelp Property

True if the Office Assistant appears when the user presses the F1 key to display Help. Read/write Boolean.

Remarks

The AssistWithHelp property corresponds to the Respond to F1 key option under Use the Office Assistant on the Options tab in the Office Assistant dialog box.

If this property is set to False, the Help Topics dialog box appears instead of the Office Assistant.


AssistWithHelp Property Example

This example displays the Office Assistant whenever the user presses the F1 key to display Help.

With Assistant
    .On = True
    .Visible = True
    .AssistWithHelp = True
    .AssistWithAlerts = True
    .Animation = msoAnimationGetAttentionMajor
End With


AssistWithWizards Property

True if the Office Assistant provides online Help with wizards. Read/write Boolean.

Remarks

The AssistWithWizards property corresponds to the Help with wizards option under Use the Office Assistant on the Options tab in the Office Assistant dialog box.


AssistWithWizards Property Example

This example sets the Office Assistant to provide Help information about wizards.

Assistant.AssistWithWizards = True


BalloonError Property

Returns a value that indicates the last recorded balloon error. Read-only Long.

Can be one of the MsoBalloonErrorType constants listed in the following table.

Constant | Description
msoBalloonErrorBadPictureRef | The balloon contains a graphic that couldn't be displayed because the file doesn't exist or because the graphic isn't a valid .BMP or .WMF file.
msoBalloonErrorBadReference | The balloon contains an unrecognized or unsupported reference.
msoBalloonErrorBadCharacter | The balloon contains an ASCII control character other than CR or LF and less than 32.
msoBalloonErrorButtonlessModal | The balloon you attempted to display is modal, but it contains no buttons. The balloon won't be shown because it can't be dismissed.
msoBalloonErrorButtonModeless | The balloon you attempted to display is modeless, contains buttons, and has no procedure assigned to the Callback property. The balloon won't be shown because a callback procedure is required for modeless balloons.
msoBalloonErrorCharNotTopmostForModal | The modal balloon was requested by an application that isn’t the active application. Microsoft Office renders balloons for the active (topmost) application only.
msoBalloonErrorCOMFailure | The balloon could not be displayed because of a COM failure.
msoBalloonErrorNone | No error was encountered.
msoBalloonErrorOther | The balloon won't appear because some other error occurred, such as another modal balloon is already active.
msoBalloonErrorOutOfMemory | The balloon won't appear because there is insufficient memory.
msoBalloonErrorTooBig | The balloon is too big to appear on the screen.
msoBalloonErrorTooManyControls | The balloon contains more than twenty controls (check boxes or labels).


BalloonError Property Example

This example creates a balloon that generates an error. The error is generated because the balloon is created without a way to dismiss it: the button type is set to msoButtonSetNone and the default balloon mode is msoModeModal, resulting in a buttonless, modal balloon. Note that there's no way to dismiss a buttonless modal balloon.

With Application.Assistant
With .NewBalloon
    .Heading = "This will never show."
    .Text = "Imagine a balloon here."
    .Button = msoButtonSetNone
    .Show
End With
.Visible = True
If .BalloonError = msoBalloonErrorButtonlessModal Then
    MsgBox "You need a button to dismiss the balloon."
End If
End With


BalloonType Property

Returns or sets the type of balloon the Office Assistant uses. Can be one of the following MsoBalloonType constants: msoBalloonTypeButtons, msoBalloonTypeBullets, or msoBalloonTypeNumbers. When you create a Balloon object, this property is initially set to msoBalloonTypeButtons. Read/write Long.


BalloonType Property Example

This example creates an instruction balloon that explains how to select a printer. The balloon is modeless, so the user can follow the instructions in the balloon and keep the balloon visible as he or she works.

Set bln = Assistant.NewBalloon
With bln
    .Heading = "Instructions for Choosing a Printer."
    .Text = "Click OK when you've chosen a printer."
    .Labels(1).Text = "From the File menu, choose Print."
    .Labels(2).Text = "Click Setup."
    .Labels(3).Text = "Select the name of the printer."
    .BalloonType = msoBalloonTypeNumbers
    .Mode = msoModeModeless
    .Callback = "ProcessPrinter"
    .Button = msoButtonSetOK
    .Show
End With


 BeginGroup Property

BeginGroup Property

True if the specified command bar control appears at the beginning of a group of controls on the command bar. Read/write Boolean.


BeginGroup Property Example

This example begins a new group with the last control on the active menu bar.

Set myMenuBar = CommandBars.ActiveMenuBar
Set lastMenu = myMenuBar _
    .Controls(myMenuBar.Controls.Count)
lastMenu.BeginGroup = True


 BuiltIn Property

BuiltIn Property

True if the specified command bar or command bar control is a built-in command bar or control of the container application. False if it's a custom command bar or control, or if it's a built-in control whose OnAction property has been set. Read-only Boolean.


 BuiltInFace Property

BuiltInFace Property

True if the face of a command bar button control is its original built-in face. This property can only be set to True, which will reset the face to the built-in face. Read/write Boolean.


BuiltInFace Property Example

This example determines whether the face of the first control on the command bar named "Custom" is its built-in button face. If it is, the example copies the button face to the Clipboard.

Set myControl = CommandBars("My Custom Bar").Controls(1)
With myControl
    If .BuiltInFace = True Then .CopyFace
End With


Button Property

Returns or sets the type of button displayed at the bottom of the Office Assistant balloon. When you create a Balloon object, this property is initially set to msoButtonSetOK. Read/write Long.

Can be one of the following MsoButtonSetType constants:

msoButtonSetAbortRetryIgnore

msoButtonSetBackClose

msoButtonSetBackNextClose

msoButtonSetBackNextSnooze

msoButtonSetCancel

msoButtonSetNextClose

msoButtonSetNone

msoButtonSetOK

 msoButtonSetOkCancel

msoButtonSetRetryCancel

msoButtonSetSearchClose

msoButtonSetTipsOptionsClose

msoButtonSetYesAllNoCancel

msoButtonSetYesNoCancel

msoButtonSetYesNo


Button Property Example

This example displays a balloon that contains a heading, text, three region choices, and two command buttons (OK and Cancel).

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select a region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    .Show
End With


Callback Property

Sets the name of the procedure to run from a modeless balloon. Read/write String.

Remarks

The procedure you specify for the Callback property must be written to receive either two or three arguments, depending on what you use the property with. If you use the Callback property with a wizard, you must write the procedure to receive two arguments: a long integer that represents the msoBalloonButtonType value of the button that the user clicked, and a long integer that uniquely identifies the balloon. If you use the Callback property with a modeless balloon, you must write the procedure to receive three arguments: the Balloon object that called the procedure; a long integer that represents the msoBalloonButtonType value of the button the user clicked; and a long integer that uniquely identifies the balloon that called the procedure, as denoted in the balloon’s Private property.

The callback procedure must contain at least one condition under which the Close method is applied to the Balloon object that is passed to it; otherwise, the modeless balloon cannot be dismissed.

If you specify a procedure that is stored in a separate class module, you must include the module name in the value assigned to the Callback property (for example, "Sheet1.MyCallback).


Callback Property Example

This example displays a balloon that contains a button for each of three printers. Whenever the user clicks one of these buttons, the ProcessPrinter callback procedure is run and the balloon is closed.

Sub selectPrinter()
Set bln = Assistant.NewBalloon
With bln
    .Heading = "Select a Printer."
    .Labels(1).Text = "Network Printer"
    .Labels(2).Text = "Local Printer"
    .Labels(3).Text = "Local Color Printer"
    .BalloonType = msoBalloonTypeButtons
    .Mode = msoModeModeless
    .Callback = "ProcessPrinter"
    .Show
End With
End Sub

Sub ProcessPrinter(bln As Balloon, lbtn As Long, _
 lPriv As Long)
    Assistant.Animation = msoAnimationPrinting
    Select Case lbtn
    Case -1
        ' Insert network printer-specific code.
    Case -2
        ' Insert local printer-specific code.
    Case -3
        ' Insert color printer-specific code.
    End Select
    bln.Close
End Sub


 Caption Property

Caption Property

Returns or sets the caption text for a command bar control. Read/write String.

Note A control's caption is also displayed as its default ScreenTip.


Caption Property Example

This example adds a command bar control with a spelling checker button face to a custom command bar, and then it sets the caption to "Spelling checker."

Set myBar = CommandBars.Add(Name:="Custom", _
Position:=msoBarTop, Temporary:=True)
myBar.Visible = True
Set myControl = myBar.Controls _
.Add(Type:=msoControlButton, Id:=2)
With myControl
    .DescriptionText = "Starts the spelling checker"
    .Caption = "Spelling checker"
End With


Checkboxes Property

Returns the BalloonCheckboxes collection that represents all the check boxes contained in the specified balloon. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.


Checkboxes Property Example

This example creates a balloon with a heading, text, and three region choices. When the user clicks OK in the balloon, data for the selected region or regions is printed.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select the region(s) you want to print."
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    If .Show = msoBalloonButtonOK Then
        dataPrinted = 0
        For i = 1 To 3
            If .CheckBoxes(i).Checked = True Then
                ' Code to print region data.
                dataPrinted = dataPrinted + 1
                MsgBox "Region " & i & " data printed."
            End If
        Next
        If dataPrinted = 0 Then MsgBox "No data printed."
    End If
End With


Checked Property

True if the specified check box in the Office Assistant balloon is checked. Read/write Boolean.


Checked Property Example

This example creates a balloon with a heading, text, and three region choices. When the user clicks OK in the balloon, data for the selected region or regions is printed.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select the region(s) you want to print."
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    If .Show = msoBalloonButtonOK Then
        dataPrinted = 0
        For i = 1 To 3
            If .CheckBoxes(i).Checked = True Then
                ' Code to print region data.
                dataPrinted = dataPrinted + 1
                MsgBox "Region " & i & " data printed."
            End If
        Next
        If dataPrinted = 0 Then MsgBox "No data printed."
    End If
End With


 CommandBar Property

CommandBar Property

Returns a CommandBar object that represents the menu displayed by the specified pop-up control. Read-only.


CommandBar Property Example

This example sets the variable fourthLevel to the fourth control on the command bar named "Drawing."

Set fourthLevel = CommandBars("Drawing") _
    .Controls(1).CommandBar.Controls(4)


Condition Property

Returns the condition of the specified search criteria. Read-only Variant.

Can be one of the following MsoCondition constants:

msoConditionAnyNumberBetween

msoConditionAnytime

msoConditionAnytimeBetween

msoConditionAtLeast

msoConditionAtMost

msoConditionBeginsWith

msoConditionDoesNotEqual

msoConditionEndsWith

msoConditionEquals

msoConditionFileTypeAllFiles

msoConditionFileTypeBinders

msoConditionFileTypeDatabases

msoConditionFileTypeExcelWorkbooks

msoConditionFileTypeOfficeFiles

msoConditionFileTypePowerPointPresentations

msoConditionFileTypeTemplates

msoConditionFileTypeWordDocuments

msoConditionIncludesNearEachOther

msoConditionIncludesPhrase

msoConditionInTheLast

 msoConditionInTheNext

msoConditionIsExactly

msoConditionIsNo

msoConditionIsNot

msoConditionIsYes

msoConditionLastMonth

msoConditionLastWeek

msoConditionLessThan

msoConditionMoreThan

msoConditionNextMonth

msoConditionNextWeek

msoConditionOn

msoConditionOnorAfter

msoConditionOnorBefore

msoConditionThisMonth

msoConditionThisWeek

msoConditionToday

msoConditionTomorrow

msoConditionYesterday


Condition Property Example

This example returns the condition value for search criteria for the first property test.

With Application.FileSearch.PropertyTests(1)
    MsgBox "The condition you've set is: " & .Condition
End With


Connect Property

Returns or sets the state of the connection for the specified COMAddIn object. Read/write Boolean.

Remarks

The Connect property returns True if the add-in is active; it returns False if the add-in is inactive. An active add-in is registered and connected; an inactive add-in is registered but not currently connected.


Connector Property

Returns the connector between two similar property test values. Can be either of the following MsoConnector constants: msoConnectorAnd or msoConnectorOr. The default value is msoConnectorAnd. Read-only Variant.

Remarks

A connector specifies whether two similar search criteria will be combined to form one property test (as with msoConnectorAnd) or treated independently (as with msoConnectorOr).


Connector Property Example

This example displays a message that describes how the search criteria will be evaluated in a file search.

With Application.FileSearch.PropertyTests(1)
If .Connector = msoConnectorAnd Then
   MsgBox "All search criteria will be combined."
Else
    MsgBox "Criteria will be treated independently"
End If
End With


 Context Property

Context Property

Returns or sets a string that determines where a command bar will be saved. The string is defined and interpreted by the application. Read/write String.

Remarks

You can set the Context property only for custom command bars. This property will fail if the application doesn't recognize the context string, or if the application doesn't support changing context strings programmatically.


Context Property Example

This example displays a message box containing the context string for the command bar named “Custom”. This example works in Microsoft Word and other applications that support the Context property.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlButton, ID:=2
    .Visible = True
End With
MsgBox (myBar.Context)


Controls Property

Returns a CommandBarControls object that represents all the controls on a command bar or pop-up control. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.


Controls Property Example

This example adds a combo box control to the command bar named "Custom" and fills the list with two items. The example also sets the number of line items, the width of the combo box, and an empty default for the combo box.

Set myControl = CommandBars("Custom").Controls _
    .Add(Type:=msoControlComboBox, Before:=1)
With myControl
    .AddItem Text:="First Item", Index:=1
    .AddItem Text:="Second Item", Index:=2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
End With


Count Property

Returns the number of items in the specified collection. Read-only Long.

Remarks

For the CommandBars collection, the count includes only menu bars, toolbars, and shortcut menus.

For the Scripts collection, the count returned is the number of script blocks in the specified document. In Word, Scripts.Count returns the total number of inline and floating script anchors combined.


Count Property Example

This example uses the Count property to display the number of command bars in the CommandBars collection.

MsgBox "There are " & CommandBars.Count & _
    " bars in the CommandBars collection."

This example uses the Count property to display the number of check boxes in the Office Assistant balloon.

With Assistant.NewBalloon
    .CheckBoxes(1).Text = "First Choice"
    .CheckBoxes(2).Text = "Second Choice"
    .Text = "You have the following " _
    & .CheckBoxes.Count & " choices."
    .Show
End With

This example displays the number of custom document properties in the active document.

MsgBox ("There are " & _
    ActiveDocument.CustomDocumentProperties.Count & _
    " custom document properties in the " & _
    "active document.")


Creator Property

Returns the four-character code for the application in which the specified object was created. Macintosh only. Read-only Long.


Description Property

Returns or sets a descriptive string for the specified COMAddIn object. Read/write String.


 DescriptionText Property

DescriptionText Property

Returns or sets the description for a command bar control. The description is not displayed to the user, but it can be useful for documenting the behavior of the control for other developers. Read/write String.

Remarks

This property is used for Balloon Help on the Macintosh.


DescriptionText Property Example

This example adds a control to a custom command bar, including a description of the control's behavior.

Set myBar = CommandBars.Add("Custom", msoBarTop, , True)
myBar.Visible = True
Set myControl = myBar.Controls _
    .Add(Type:=msoControlButton, ID:= _
    CommandBars("Standard").Controls("Paste").ID)
With myControl
    .DescriptionText = "Pastes the contents of the Clipboard"
    .Caption = "Paste"
End With


DisplayFonts Property

True if the font names in the Font box are displayed in their actual fonts. Read/write Boolean.


DisplayFonts Property Example

This example sets three options for all command bars in Microsoft Office, including custom command bars and the controls on them.

With CommandBars
    .LargeButtons = True
    .DisplayFonts = True
    .AdaptiveMenus = True
End With


 DisplayKeysInTooltips Property

DisplayKeysInTooltips Property

True if shortcut keys are displayed in the ToolTips for each command bar control. Read/write Boolean.

Remarks

To display shortcut keys in ToolTips, you must also set the DisplayTooltips property to True.


DisplayKeysInTooltips Property Example

This example sets options for all command bars in Microsoft Office.

With CommandBars
    .LargeButtons = True
    .DisplayTooltips = True
    .DisplayKeysInTooltips = True
    .MenuAnimationStyle = msoMenuAnimationUnfold
End With


 DisplayTooltips Property

DisplayTooltips Property

True if ScreenTips are displayed whenever the user positions the pointer over command bar controls. Read/write Boolean.

Remarks

Setting the DisplayTooltips property in a container application immediately affects every command bar in every running Microsoft Office application, and in every Office application opened after the property is set.


DisplayTooltips Property Example

This example displays large controls and ToolTips on all command bars.

Set allBars = CommandBars

allBars.LargeButtons = True
allBars.DisplayTooltips = True


 DropDownLines Property

DropDownLines Property

Returns or sets the number of lines in a command bar combo box control. The combo box control must be a custom control and it must be a drop-down list box or a combo box. Read/write Long.

Note An error occurs if you attempt to set this property for a combo box control that's an edit box or a built-in combo box control.

Remarks

If this property is set to 0 (zero), the number of lines in the control will be based on the number of items in the list.


DropDownLines Property Example

This example adds a combo box control containing two items to the command bar named "Custom". The example also sets the number of line items, the width of the combo box, and an empty default for the combo box.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls.Add(Type:=msoControlComboBox, Id:=1)
With myControl
    .AddItem Text:="First Item", Index:=1
    .AddItem "Second Item", 2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
End With


 DropDownWidth Property

DropDownWidth Property

Returns or sets the width (in pixels) of the list for the specified command bar combo box control. Read/write Long.

Note An error occurs if you attempt to set this property for a built-in control.

Remarks

If this property is set to -1, the width of the list is based on the length of the longest item in the combo box list. If this property is set to 0, the width of the list is based on the width of the control.


DropDownWidth Property Example

This example adds a combo box control containing two items to the command bar named "Custom". The example also sets the number of line items, the width of the combo box, and an empty default for the combo box.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls.Add(Type:=msoControlComboBox, Id:=1)
With myControl
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
End With


 Enabled Property

Enabled Property

True if the specified command bar or command bar control is enabled. Read/write Boolean.

Remarks

For command bars, setting this property to True causes the name of the command bar to appear in the list of available command bars.

For built-in controls, if you set the Enabled property to True, the application determines its state, but setting it to False will force it to be disabled.


Enabled Property Example

This example adjusts the command bars according to the user level specified by user. If user is "Level 1," the command bar named "VB Custom Bar" is displayed. If user is any other value, the built-in Visual Basic command bar is reset to its default state and the command bar named "VB Custom Bar" is disabled.

Set myBar = CommandBars _
    .Add(Name:="VB Custom Bar", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlButton, ID:=2
    .Visible = True
End With
If user = "Level 1" Then
    myBar.Visible = True
Else
    CommandBars("Visual Basic").Reset
    myBar.Enabled = False
End If

This example adds two command bar buttons to the command bar named “Custom”. The first control is disabled; the second control is enabled by default.

Set myBar = CommandBars("Custom")
With myBar
    .Controls.Add Type:=msoControlButton, Id:=3
    .Controls(1).Enabled = False
    .Controls.Add Type:=msoControlButton, Id:=3
End With
myBar.Visible = True


Extended Property

Sets or returns attributes added to the <SCRIPT> tag, with the exception of the LANGUAGE and ID attributes. Read/write String.

Remarks

Attributes are separated by spaces, the same as in HTML. You cannot pass the LANGUAGE attribute or the ID attribute by using the Extended property.

The Microsoft Office host application doesn’t provide any means of checking the syntax of passed attributes.

If you pass the LANGUAGE attribute in the Extended property, the <SCRIPT> tag receives two language settings, which causes a conflict.

If you pass an ID attribute in the Extended property and no ID has been set through either the ID parameter of the Add method or the Id property of the Script object, the ID is exported correctly.


Extended Property Example

This example checks the Extended property to ensure that no additional attributes have been added to the first script in worksheet one in the active workbook.

If ActiveWorkbook.Worksheets(1).Scripts(1).Extended _
    <> "" Then
      MsgBox "This script contains extended attributes."
End If


 FaceId Property

FaceId Property

Returns or sets the Id number for the face of a command bar button control. Read/write Long.

Remarks

The FaceId property dictates the look, not the function, of a command bar button. The Id property of the CommandBarControl object determines the function of the button.

The value of the FaceId property for a command bar button with a custom face is 0 (zero).


FaceId Property Example

This example adds a command bar button to a custom command bar. Clicking this button is equivalent to clicking the Open command on the File menu because the ID number is 23, yet the button has the same button face as the built-in Charting button.

Set newBar = CommandBars.Add(Name:="Custom2", _
     Position:=msoBarTop, Temporary:=True)
newBar.Visible = True
Set con = newBar.Controls.Add(Type:=msoControlButton, Id:=23)
con.FaceId = 17


FeatureTips Property

True if the Office Assistant provides information about using application features more effectively. Read/write Boolean.

Remarks

The FeatureTips property corresponds to the Using features more effectively check box on the Options tab in the Assistant dialog box.


FeatureTips Property Example

This example allows the Office Assistant to provide information about using application features more effectively.

Assistant.FeatureTips = True


FileName Property

Assistant object: Returns or sets the path and file name for the active Office Assistant. Read/write String.

FileSearch object: Returns or sets the name of the file to look for during a file search. The name of the file may include the * (asterisk) or ? (question mark) wildcards. Use the question mark wildcard to match any single character. For example, type gr?y to match both "gray" and "grey." Use the asterisk wildcard to match any number of characters. For example, type *.txt to find all files that have the .TXT extension. Read/write String.

Remarks

In Windows, the file name extension for Assistant files is .acs. The files are installed in the \Program Files\Microsoft Office\Office folder in Windows 95, Windows 98, and Windows NT.

The following file names correspond to seven of the Assistants provided in Microsoft Office 2000. Additional Assistant choices may be available, depending on the language settings on an individual computer.

Character | File name
Clippit | Clippit.acs
Links | OffCat.acs
Rocky | Rocky.acs
Office Logo | Logo.acs
The Dot | Dot.acs
Mother Nature | MNature.acs
F1 | F1.acs


FileName Property Example

This example searches for all files located in the My Documents folder that begin with "cmd" and have a file name extension. The example displays the name and location of each found file.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "cmd*.*"
    If .Execute > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


Files Property

Returns an AnswerWizardFiles collection that represents the list of files available to the current AnswerWizard. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.


Files Property Example

This example resets the file list for the current AnswerWizard and then displays both the file count and the file names in a message box.

Dim customAnswerWizard As AnswerWizard
Dim strFileList As String
Dim intCounter As Integer
Dim intNumFiles As Integer

Set customAnswerWizard = Application.AnswerWizard
intCounter = 1

customAnswerWizard.ResetFileList
strFileList = ""
intNumFiles = customAnswerWizard.Files.Count
For intCounter = 1 To (intNumFiles)
    strFileList = strFileList & _
    customAnswerWizard.Files.Item(intCounter) & Chr(13)
Next

MsgBox "There are " & customAnswerWizard.Files.Count & _
    " files avaialble through this AnswerWizard: " & _
    Chr(13) & strFileList


FileType Property

FileSearch object: Returns or sets the type of file to look for during a file search. Can be one of the following MsoFileType constants: msoFileTypeAllFiles, msoFileTypeBinders, msoFileTypeDatabases, msoFileTypeExcelWorkbooks, msoFileTypeOfficeFiles, msoFileTypePowerPointPresentations, msoFileTypeTemplates, or msoFileTypeWordDocuments. The default value is msoFileTypeOfficeFiles. Read/write Variant.

Remarks

The constant msoFileTypeOfficeFiles includes all files with any of the following extensions: *.doc, *.xls, *.ppt, *.pps, *.obd, *.mdb, *.mpd, *.dot, *.xlt, *.pot, *.obt, *.htm, or *.html.


FileType Property Example

This example searches for all Binder files located in the My Documents folder. The example displays a message box that contains the name and location of each file that’s found.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileType = msoFileTypeBinders
    If .Execute > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " Binder file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no Binder files found."
    End If
End With


FixedWidthFont Property

Sets or returns the fixed-width font setting in the host application. Read/write String.

Remarks

When you set the FixedWidthFont property, the host application does not check the value for validity.


FixedWidthFontSize Property

Sets or returns the fixed-width font size setting in the host application, in points. Read/write Single.

Remarks

When you set the FixedWidthFontSize property, the host application does not check the value for validity. If you enter an invalid value, such as a nonnumber, the host application sets the size to 0 points. You can enter half-point sizes; if you enter other fractional point sizes, they are rounded up or down to the nearest half-point.


FixedWidthFontSize Property Example

This example sets the fixed-width font and fixed-width font size for the English/Western European/Other Latin Script character set in the active application.

Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.FixedWidthFont = "System"
Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.FixedWidthFontSize = 12


FoundFiles Property

Returns a FoundFiles object that contains the names of all the files found during a search. Read-only.


FoundFiles Property Example

This example steps through the list of files found during a search and displays the path for each file.

With Application.FileSearch
For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
Next I
End With


GuessHelp Property

True if the Office Assistant balloon presents a list of Help topics based on keywords the user selects before clicking the Assistant window or pressing F1. Read/write Boolean.

Remarks

The GuessHelp property corresponds to the Guess help topics option under Use the Office Assistant on the Options tab in the Office Assistant dialog box.


GuessHelp Property Example

This example allows the Office Assistant to guess at Help topics.

Assistant.GuessHelp = True


Guid Property

Returns the globally unique class identifier (GUID) for the specified COMAddIn object. Read-only String.


Guid Property Example

The following example displays the ProgID and GUID for COM add-in one in a message box.

MsgBox "My ProgID is " & _
    Application.COMAddIns(1).ProgID & _
    " and my GUID is " & _
    Application.COMAddIns(1).Guid


Heading Property

Returns or sets the heading that appears in the Office Assistant balloon. Read/write String.

Remarks

You can specify a graphic to be displayed in the balloon heading by using the following syntax: {type location sizing_factor}, where type is bmp (bitmap) or wmf (Windows metafile), location is the resource ID or the path and file name, and sizing_factor specifies the width of the wmf (omitted for bmp).

The balloon heading also supports underlined text and text that has one of the 16 system palette colors applied to it. To display underlined text in a heading, use the syntax {ul} or {ul 1}; use {ul 0} to turn underlining off. To change the color of heading text, precede the text string with the character sequence {cf number}, where number is one of the system color numbers listed in the following table.

System color number | Color
0 | Black
1 | Dark red
2 | Dark green
3 | Dark yellow
4 | Dark blue
5 | Dark magenta
6 | Dark cyan
7 | Light gray
248 | Medium gray
249 | Red
250 | Green
251 | Yellow
252 | Blue
253 | Magenta
254 | Cyan
255 | White

If you specify a number other than one of the preceding system color numbers, the heading text is black.


Heading Property Example

This example displays a balloon with a heading, text, and three region choices.

With Assistant.NewBalloon
    .Button = msoButtonSetOkCancel
    .Heading = "Regional Sales Data"
    .Text = "Select a region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Show
End With


 Height Property

Height Property

Returns or sets the height of a command bar control, in pixels. Read/write Long. For command bars, the Height property is read-only.


Height Property Example

This example adds a custom control to the command bar named "Custom". The example sets the height of the custom control to twice the height of the command bar and sets the control’s width to 50 pixels. Notice how the command bar automatically resizes itself to accommodate the control.

Set myBar = CommandBars("Custom")
barHeight = myBar.Height
Set myControl = myBar.Controls _
    .Add(Type:=msoControlButton, _
    Id:= CommandBars("Standard").Controls("Save").Id, _
     Temporary:=True)
With myControl
    .Height = barHeight * 2
    .Width = 50
End With
myBar.Visible = True


 HelpContextId Property

HelpContextId Property

Returns or sets the Help context Id number for the Help topic attached to the command bar control. Read/write Long.

Remarks

To use this property, you must also set the HelpFile property. Help topics respond to Shift+F1.


HelpContextId Property Example

This example adds a custom command bar with a combo box that tracks stock data. The example also specifies the Help topic to be displayed for the combo box when the user presses SHIFT+F1.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
With CommandBars("Custom").Controls(1)
    .AddItem "Get Stock Quote", 1
    .AddItem "View Chart", 2
    .AddItem "View Fundamentals", 3
    .AddItem "View News", 4
    .Caption = "Stock Data"
    .DescriptionText = "View Data For Stock"
    .HelpFile = "C:\corphelp\custom.hlp"
    .HelpContextID = 47
End With


 HelpFile Property

HelpFile Property

Returns or sets the file name for the Help topic attached to the command bar control. Read/write String.

Remarks

To use this property, you must also set the HelpContextID property. Help topics respond to the user pressing SHIFT+F1.


HelpFile Property Example

This example adds a custom command bar with a combo box that tracks stock data. The example also specifies the Help topic to be displayed for the combo box when the user presses SHIFT+F1.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
With CommandBars("Custom").Controls(1)
    .AddItem "Get Stock Quote", 1
    .AddItem "View Chart", 2
    .AddItem "View Fundamentals", 3
    .AddItem "View News", 4
    .Caption = "Stock Data"
    .DescriptionText = "View Data For Stock"
    .HelpFile = "C:\corphelp\custom.hlp"
    .HelpContextID = 47
End With


HighPriorityTips Property

True if the Office Assistant displays high-priority tips. Read/write Boolean.

Remarks

The HighPriorityTips property corresponds to the Only show high priority tips option under Show tips about on the Options tab in the Office Assistant dialog box.


HighPriorityTips Property Example

This example sets the Office Assistant to display high-priority tips.

Assistant.HighPriorityTips = True


HTMLProjectItems Property

Returns the HTMLProjectItems collection that is included in the specified HTML project. Read-only HTMLProjectItems.


HTMLProjectItems Property Example

This example returns the number of items in the HTMLProjectItems collection in the HTML project in the active workbook.

intCount = ActiveWorkbook.HTMLProject.HTMLProjectItems.Count


HyperlinkType Property

Sets or returns the type of hyperlink associated with the specified command bar button. Can be one of the following MsoCommandBarButtonHyperlinkType constants: msoCommandBarButtonHyperlinkNone, msoCommandBarButtonHyperlinkOpen, or msoCommandBarButtonHyperlinkInsertPicture. Read/write Long.


HyperlinkType Property Example

This example checks the HyperlinkType property for the specified command bar button on the command bar named "Custom.". If HyperlinkType is set to msoCommandBarButtonHyperlinkNone, the example sets the property to msoCommandBarButtonHyperlinkOpen and sets the URL to www.microsoft.com.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
Set myButton = myBar.Controls.Add(Type:=msoControlButton)
With myButton
    .FaceId = 277
    .HyperlinkType = msoCommandBarButtonHyperlinkNone
End With
If myButton.HyperlinkType <> _
    msoCommandBarButtonHyperlinkOpen Then
    myButton.HyperlinkType = _
        msoCommandBarButtonHyperlinkOpen
    myButton.TooltipText = "www.microsoft.com"
End If


Icon Property

Returns or sets the type of icon that appears in the upper-left portion of the Office Assistant balloon. Can be one of the following MsoIconType constants: msoIconAlert, msoIconAlertCritical, msoIconAlertInfo, msoIconAlertQuery, msoIconAlertWarning, msoIconNone, or msoIconTip. Read/write String.


Icon Property Example

This example creates a balloon with an “Alert” icon that instructs the user to select a printer.

With Assistant.NewBalloon
    .Heading = "Select A Printer"
    .Text = "You must select a printer before printing."
    .Icon = msoIconAlert
    .CheckBoxes(1).Text = "Local printer"
    .CheckBoxes(2).Text = "Network printer"
    .Show
End With


Id Property

Returns the Id of an object. Select one of the following objects to see a detailed description of the Id property for that object.

CommandBarControl
Script


Index Property

Returns the index number for an object in the collection.. Read-only Long.

Remarks

The position of the first command bar control is 1. Separators are not counted in the CommandBarControls collection.


Index Property Example

This example searches the command bar named "Custom2" for a control with an Id value of 23. If such a control is found and the index number of the control is greater than 5, the control will be positioned as the first control on the command bar.

Set myBar = CommandBars("Custom2")
Set ctrl1 = myBar.FindControl(Id:=23)
If ctrl1.Index > 5 Then
    ctrl1.Move before:=1
End If


IsOpen Property

True if the specified HTML project item is open in the Microsoft Script Editor. Read-only Boolean.


IsOpen Property Example

This example determines whether the specified HTML project item is open. and if it is, the example then loads script from the specified file.

If ActiveWorkbook.HTMLProject.HTMLProjectItems _
    .Item(1).IsOpen Then
    ActiveWorkbook.HTMLProject.HTMLProjectItems _
        .Item(1).LoadFromFile ("C:\MyScript.txt")
Else
    MsgBox "The HTMLProjectItem is not open."
End If


IsPriorityDropped Property

True if the control is currently dropped from the menu or toolbar based on usage statistics and layout space. (Note that this is not the same as the control's visibility, as set by the the Visible property.) A control with Visible set to True, will not be immediately visible on a Personalized Menu or Toolbar if IsPriorityDropped is True. Read-only Boolean.

Remarks

To determine when to set IsPriorityDropped to True for a specific menu item, Microsoft Office maintains a total count of the number of times the menu item was used and a record of the number of different application sessions in which the user has used another menu item in the same menu as this menu item, without using the specific menu item. When this value reaches certain threshold values, the count is decremented. When the count reaches zero, IsPriorityDropped is set to True. Programmers cannot set the session value, the threshold value, or the IsPriorityDropped property. Programmers can, however, use the AdaptiveMenus property to disable adaptive menus for specific menus in an application.

To determine when to set IsPriorityDropped to True for a specific toolbar control, Office maintains a list of the order in which all the controls on that toolbar were last executed. A toolbar will always show as many controls as it has space to show, in the order of most recently used to least recently used. Controls with Priority set to 1 will always be shown and the toolbar will wrap rows, if necessary, to show these controls. Programmers can use the Priority property to ensure that specific toolbar controls are always shown, or to reposition toolbars so that they have enough space to display all of their controls.

You can use the following table to predict the number of sessions for which a menu item on a Personalized Menu will remain visible before the menu item's IsPriorityDropped property is set to True.

Number of uses of the command bar control | Number of sessions of the application
0, 1 | 3
2 | 6
3 | 9
4, 5 | 12
6– 8 | 17
9–13 | 23
14–24 | 29
25 or more | 31


IsPriorityDropped Property Example

This example checks the IsPriorityDropped property for the first control on the command bar named “Custom.” If IsPriorityDropped is True, the example sets the AdaptiveMenus property to False, restoring the dropped command bar.

If CommandBars("Custom").Controls(1).IsPriorityDropped Then
    CommandBars.AdaptiveMenus = True
End If


Item Property

Returns an object from a collection, or returns text associated with an object.

Item is the default member of the object or collection. For example, the following two statements both assign a CommandBar object to cmdBar.

Set cmdBar = CommandBars.Item("Standard")
Set cmdBar = CommandBars("Standard")

The following two statements both assign the text of the first label in the Balloon object assigned to myBalloon to lblText.

lblText = myBalloon.Labels(1).Item
lblText = myBalloon.Labels(1)

Select one of the following objects to see a detailed description of the Item property for that object:

AnswerWizardFiles

Assistant

BalloonCheckboxes

BalloonCheckbox

BalloonLabel

BalloonLabels

COMAddIns

CommandBarControls

CommandBars

DocumentProperties

FoundFiles

HTMLProjectItems

PropertyTests

Scripts

WebPageFonts


Item Property (AnswerWizardFiles Collection Object)

Returns a file name string from an AnswerWizardFiles collection. Read-only.

Syntax

expression.Item(Index)

expression Required. An expression that returns an AnswerWizardFiles collection.

Index Required Integer. The index number of the AnswerWizard file name string to be returned.


Item Property (AnswerWizardFiles Collection Object) Example

This example resets the file list for the current AnswerWizard and displays both the file count and the file names in a message box, using the Item property to return the file names.

Dim customAnswerWizard As AnswerWizard
Dim strFileList As String
Dim intCounter As Integer
Dim intNumFiles As Integer

Set customAnswerWizard = Application.AnswerWizard
intCounter = 1

customAnswerWizard.ResetFileList
strFileList = ""
intNumFiles = customAnswerWizard.Files.Count
For intCounter = 1 To (intNumFiles)
    strFileList = strFileList & _
    customAnswerWizard.Files.Item(intCounter) & Chr(13)
Next

MsgBox "There are " & customAnswerWizard.Files.Count & _
    " files avaialble through this AnswerWizard: " & _
    Chr(13) & strFileList


Item Property (Assistant, BalloonLabel, and BalloonCheckBox Objects)

Returns the text associated with an object. Read-only String.

Syntax

expression.Item

expression Required. An expression that returns an Assistant, BalloonCheckBox, or BalloonLabel object.


Item Property (BalloonCheckBoxes Collection)

Returns a BalloonCheckBox object from the BalloonCheckBoxes collection. Read-only.

Syntax

expression.Item(Index)

expression An expression that returns a BalloonCheckBox object.

Index Required Long. The index number of the check box to be returned.


Item Property (BalloonLabels Collection)

Returns a BalloonLabel object from the BalloonLabels collection. Read-only.

Syntax

expression.Item(Index)

expression An expression that returns a BalloonLabel object.

Index Required Long. The index number of the label to be returned.


Item Property (CommandBars and CommandBarControls Collections)

Returns a CommandBar object from the CommandBars collection, or returns a CommandBarControl object from the CommandBarControls collection. Read-only.

Syntax

expression.Item(Index)

expression Required. An expression that returns a CommandBar or CommandBarControl object.

Index Required Variant. The name or index number of the object to be returned. Note that you can only use index numbers to return PropertyTest objects from the PropertyTests collection.


Item Property (DocumentProperties Collection)

Returns an DocumentProperty object from the DocumentProperties collection. Read-only.

Syntax

expression.Item(Index)

expression Required. An expression that returns a DocumentProperty object.

Index Required Variant. The name or index number of the document property returned.


Item Property (FoundFiles Object)

Returns a file name from the list of file names represented by the FoundFiles object. Read-only String.

Syntax

expression.Item(Index)

expression Required. An expression that returns a FoundFiles object.

Index Required Variant. The index number of the file name to be returned.


Item Property (PropertyTests Collection)

Returns an PropertyTest object from the PropertyTests collection. Read-only.

Syntax

expression.Item(Index)

expression Required. An expression that returns a PropertyTest object.

Index Required Variant. The index number of the property test to be returned.


Item Property (WebPageFonts Object)

Returns a WebPageFont object from the WebPageFonts collection for a particular value of MsoCharacterSet. Read-only Object.

Remarks

The WebPageFonts collection contains one WebPageFont object for each of the following MsoCharacterSet constants:

msoCharacterSetArabic
msoCharacterSetCyrillic
msoCharacterSetEnglishWesternEuropeanOtherLatinScript
msoCharacterSetGreek
msoCharacterSetHebrew
msoCharacterSetJapanese
msoCharacterSetKorean
msoCharacterSetMultilingualUnicode
msoCharacterSetSimplifiedChinese
msoCharacterSetThai
msoCharacterSetTraditionalChinese
msoCharacterSetVietnamese


Item Property (WebPageFonts Object) Example

The following example uses the Item property to set myFont to the WebPageFont object for the English/Western European/Other Latin Script character set in the active application.

Dim myFont As WebPageFont
Set myFont = _
  Application.DefaultWebOptions.Fonts. _
  Item(msoCharacterSetEnglishWesternEuropeanOtherLatinScript)


KeyboardShortcutTips Property

True if the Office Assistant displays Help about keyboard shortcuts. Read/write Boolean.

Remarks

The KeyboardShortcutTips property corresponds to the Keyboard shortcuts option in the Show tips about section on the Options tab in the Office Assistant dialog box.


KeyboardShortcutTips Property Example

This example sets the Office Assistant to provide Help information about keyboard shortcuts.

Assistant.KeyboardShortcutTips = True


Labels Property

Returns a BalloonLabels collection that represents the button labels, number labels, and bullet labels contained in the specified Office Assistant balloon. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.


Labels Property Example

This example creates a balloon containing three choices. The variable x is set to the return value of the Show method, which will be 1, 2 or 3, depending on the label the user clicks. In the example, a message box displays the value of the variable x, but you can pass the value to another procedure or you can use the value in a Select Case statement.

Set b = Assistant.NewBalloon
With b
    .Heading = "This is my heading"
    .Text = "Select one of these things:"
    .Labels(1).Text = "Choice One"
    .Labels(2).Text = "Choice Two"
    .Labels(3).Text = "Choice Three"
    x = .Show
End With
MsgBox x


Language Property

Specifies or returns the scripting language of the active script. Can be one of the following MsoScriptLanguage constants: msoScriptLanguageASP, msoScriptLanguageJava, msoScriptLanguageOther, or msoScriptLanguageVisualBasic Read/write Long.

Remarks

The MsoScriptLanguage constants used with the Language property are also used in the Language parameter in the Add method of the Scripts collection.


LanguageID Property

Returns the locale identifier (LCID) for the install language, the user interface language, or the Help language. Read-only Long.

Remarks

You can use one of the MsoAppLanguageID constants listed in the following table to return LCID information to the application.

MsoAppLanguageID constant | Meaning
msoLanguageIDExeMode | The language mode that the application is using. This setting applies only to Microsoft Excel and Microsoft Access. This setting affects languages that can be displayed and edited, available language-specific features, number styles, currency settings, and so forth. If none of the languages supported by Excel and Access are used, the host application will not be configured to support right-to-left and East Asian languages. The supported languages are as follows: Arabic Farsi Hebrew Japanese Korean Simplified Chinese Traditional Chinese Urdu Yiddish
msoLanguageIDHelp | The language used for online Help.
msoLanguageIDInstall | The language settings used by Microsoft Office to set up defaults. For example, Microsoft Word uses this setting to determine the layout of toolbars and the default types of bullets and numbers on a language-by-language basis.
msoLanguageIDUI | The language used by the host application's user interface.
msoLanguageIDUIPrevious | The language setting for the user interface when a given computer was last rebooted. A program or add-in can use this to determine whether the user interface language has changed.


LanguageID Property Example

This Microsoft Excel example checks the LanguageID property settings for the user interface and execution mode to verify that they are set to the same LCID. The example returns an error if there is a discrepancy.

If Application.LanguageSettings.LanguageID(msoLanguageIDExeMode) _
    <> Application.LanguageSettings.LanguageID(msoLanguageIDUI) _
    Then MsgBox "The user interface language and execution " & _
    "mode are different."


LanguagePreferredForEditing Property

Returns True if the value for the msoLanguageID constant has been identified in the Windows registry as a preferred language for editing. Read-only Boolean.

Remarks

You must test all valid msoLanguageID values to enumerate the set of preferred languages.

The following list contains all of the valid MsoLanguageID constants:

msoLanguageIDAfrikaans
msoLanguageIDAlbanian
msoLanguageIDArabic
msoLanguageIDArabicAlgeria
msoLanguageIDArabicBahrain
msoLanguageIDArabicEgypt
msoLanguageIDArabicIraq
msoLanguageIDArabicJordan
msoLanguageIDArabicKuwait
msoLanguageIDArabicLebanon
msoLanguageIDArabicLibya
msoLanguageIDArabicMorocco
msoLanguageIDArabicOman
msoLanguageIDArabicQatar
msoLanguageIDArabicSyria
msoLanguageIDArabicTunisia
msoLanguageIDArabicUAE
msoLanguageIDArabicYemen
msoLanguageIDArmenian
msoLanguageIDAssamese
msoLanguageIDAzeriCyrillic
msoLanguageIDAzeriLatin
msoLanguageIDBasque
msoLanguageIDBelgianDutch
msoLanguageIDBelgianFrench
msoLanguageIDBengali
msoLanguageIDBosniaHerzegovina
msoLanguageIDBrazilianPortuguese
msoLanguageIDBulgarian
msoLanguageIDBurmese
msoLanguageIDByelorussian
msoLanguageIDCatalan
msoLanguageIDChineseHongKong
msoLanguageIDChineseMacao
msoLanguageIDChineseSingapore
msoLanguageIDCroatian
msoLanguageIDCzech
msoLanguageIDDanish
msoLanguageIDDutch
msoLanguageIDEnglishAUS
msoLanguageIDEnglishBelize
msoLanguageIDEnglishCanadian
msoLanguageIDEnglishCaribbean
msoLanguageIDEnglishIreland
msoLanguageIDEnglishJamaica
msoLanguageIDEnglishNewZealand
msoLanguageIDEnglishPhilippines
msoLanguageIDEnglishSouthAfrica
msoLanguageIDEnglishTrinidad
msoLanguageIDEnglishUK
msoLanguageIDEnglishUS
msoLanguageIDEnglishZimbabwe
msoLanguageIDEstonian
msoLanguageIDFaeroese
msoLanguageIDFarsi
msoLanguageIDFinnish
msoLanguageIDFrench
msoLanguageIDFrenchCameroon
msoLanguageIDFrenchCanadian
msoLanguageIDFrenchCotedIvoire
msoLanguageIDFrenchLuxembourg
msoLanguageIDFrenchMali
msoLanguageIDFrenchMonaco
msoLanguageIDFrenchReunion
msoLanguageIDFrenchSenegal
msoLanguageIDFrenchWestIndies
msoLanguageIDFrenchZaire
msoLanguageIDFrisianNetherlands
msoLanguageIDGaelicIreland
msoLanguageIDGaelicScotland
msoLanguageIDGalician
msoLanguageIDGeorgian
msoLanguageIDGerman
msoLanguageIDGermanAustria
msoLanguageIDGermanLiechtenstein
msoLanguageIDGermanLuxembourg
msoLanguageIDGreek
msoLanguageIDGujarati
msoLanguageIDHebrew
msoLanguageIDHindi
msoLanguageIDHungarian
msoLanguageIDIcelandic
msoLanguageIDIndonesian
msoLanguageIDItalian
msoLanguageIDJapanese
msoLanguageIDKannada
msoLanguageIDKashmiri
msoLanguageIDKazakh
msoLanguageIDKhmer
msoLanguageIDKirghiz
msoLanguageIDKonkani
msoLanguageIDKorean
msoLanguageIDLao
msoLanguageIDLatvian
msoLanguageIDLithuanian
msoLanguageIDLithuanianClassic
msoLanguageIDMacedonian
msoLanguageIDMalayalam
msoLanguageIDMalayBruneiDarussalam
msoLanguageIDMalaysian
msoLanguageIDMaltese
msoLanguageIDManipuri
msoLanguageIDMarathi
msoLanguageIDMexicanSpanish
msoLanguageIDMixed
msoLanguageIDMongolian
msoLanguageIDNepali
msoLanguageIDNone
msoLanguageIDNoProofing
msoLanguageIDNorwegianBokmol
msoLanguageIDNorwegianNynorsk
msoLanguageIDOriya
msoLanguageIDPolish
msoLanguageIDPortuguese
msoLanguageIDPunjabi
msoLanguageIDRhaetoRomanic
msoLanguageIDRomanian
msoLanguageIDRomanianMoldova
msoLanguageIDRussian
msoLanguageIDRussianMoldova
msoLanguageIDSamiLappish
msoLanguageIDSanskrit
msoLanguageIDSerbianCyrillic
msoLanguageIDSerbianLatin
msoLanguageIDSesotho
msoLanguageIDSimplifiedChinese
msoLanguageIDSindhi
msoLanguageIDSlovak
msoLanguageIDSlovenian
msoLanguageIDSorbian
msoLanguageIDSpanish
msoLanguageIDSpanishArgentina
msoLanguageIDSpanishBolivia
msoLanguageIDSpanishChile
msoLanguageIDSpanishColombia
msoLanguageIDSpanishCostaRica
msoLanguageIDSpanishDominicanRepublic
msoLanguageIDSpanishEcuador
msoLanguageIDSpanishElSalvador
msoLanguageIDSpanishGuatemala
msoLanguageIDSpanishHonduras
msoLanguageIDSpanishModernSort
msoLanguageIDSpanishNicaragua
msoLanguageIDSpanishPanama
msoLanguageIDSpanishParaguay
msoLanguageIDSpanishPeru
msoLanguageIDSpanishPuertoRico
msoLanguageIDSpanishUruguay
msoLanguageIDSpanishVenezuela
msoLanguageIDSutu
msoLanguageIDSwahili
msoLanguageIDSwedish
msoLanguageIDSwedishFinland
msoLanguageIDSwissFrench
msoLanguageIDSwissGerman
msoLanguageIDSwissItalian
msoLanguageIDTajik
msoLanguageIDTamil
msoLanguageIDTatar
msoLanguageIDTelugu
msoLanguageIDThai
msoLanguageIDTibetan
msoLanguageIDTraditionalChinese
msoLanguageIDTsonga
msoLanguageIDTswana
msoLanguageIDTurkish
msoLanguageIDTurkmen
msoLanguageIDUkrainian
msoLanguageIDUrdu
msoLanguageIDUzbekCyrillic
msoLanguageIDUzbekLatin
msoLanguageIDVenda
msoLanguageIDVietnamese
msoLanguageIDWelsh
msoLanguageIDXhosa
msoLanguageIDZulu


LanguagePreferredForEditing Property Example

This example displays a message if U.S. English is a preferred editing language.

If Application.LanguageSettings. _
    LanguagePreferredForEditing(msoLanguageIDEnglishUS) Then
    MsgBox "One of the preferred editing languages is US English."
End If


LargeButtons Property

True if the toolbar buttons displayed are larger than normal size. Read/write Boolean.


LargeButtons Property Example

This example toggles the display size of toolbar buttons on all command bars.

Set allBars = CommandBars
If allBars.LargeButtons Then
    allBars.LargeButtons = False
Else
    allBars.LargeButtons = True
End If


LastModified Property

Returns or sets a constant that represents the amount of time since the specified file was last modified and saved. Can be one of the following MsoLastModified constants: msoLastModifiedAnyTime, msoLastModifiedLastMonth, msoLastModifiedLastWeek, msoLastModifiedThisMonth, msoLastModifiedThisWeek, msoLastModifiedToday, or msoLastModifiedYesterday. The default value is msoLastModifiedAnyTime. Read/write Variant.


LastModified Property Example

This example sets options for a file search. The files this search returns were modified yesterday and are located in the C:\My Documents folder or in one of its subfolders.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .LastModified = msoLastModifiedYesterday
End With


 Left Property

Left Property

CommandBar or CommandBarControl object: Returns or sets the distance (in pixels) from the left edge of the specified command bar or command bar control to the left edge of the screen. Returns the distance from the left side of the docking area. Read/write Long for CommandBar, read-only Long for CommandBarControl.

Assistant object: Sets or returns the horizontal position of the Office Assistant window (in points), relative to the screen. Read/write Long.


Left Property Example

This example moves the custom command bar named "Custom" from its docked position along the top of the window to the left edge of the window.

Set myBar = CommandBars("Custom")
With myBar
    .Position = 1
    .RowIndex = 2
    .Left = 0
End With

This example displays the Office Assistant and moves it to the specified position within the application window.

With Assistant
    .Visible = True
    .Left = 300
    .Top = 300
End With


LinkSource Property

Returns or sets the source of a linked custom document property. Read/write String.

Remarks

This property applies only to custom document properties; you cannot use it with built-in document properties.

The source of the specified link is defined by the container application.

Setting the LinkSource property sets the LinkToContent property to True.


LinkSource Property Example

This example displays the linked status of a custom document property. For the example to work, dp must be a valid DocumentProperty object.

Sub DisplayLinkStatus(dp As DocumentProperty)
    Dim stat As String, tf As String
    If dp.LinkToContent Then
        tf = ""
    Else
        tf = "not "
    End If
    stat = "This property is " & tf & "linked"
    If dp.LinkToContent Then
        stat = stat + Chr(13) & "The link source is " & dp.LinkSource
    End If
    MsgBox stat
End Sub


LinkToContent Property

True if the value of the custom document property is linked to the content of the container document. False if the value is static. Read/write Boolean.

Remarks

This property applies only to custom document properties. For built-in document properties, the value of this property is False.

Use the LinkSource property to set the source for the specified linked property. Setting the LinkSource property sets the LinkToContent property to True.


LinkToContent Property Example

This example displays the linked status of the custom document property. For the example to work, dp must be a valid DocumentProperty object.

Sub DisplayLinkStatus(dp As DocumentProperty)
    Dim stat As String, tf As String
    If dp.LinkToContent Then
        tf = ""
    Else
        tf = "not "
    End If
    stat = "This property is " & tf & "linked"
    If dp.LinkToContent Then
        stat = stat + Chr(13) & "The link source is " & dp.LinkSource
    End If
    MsgBox stat
End Sub


 List Property

List Property

Returns or sets an item in the command bar combo box control. Read/write String.

Note This property is read-only for built-in combo box controls.

Syntax

expression.List(Index)

expression Required. An expression that returns a CommandBarComboBox object.

Index Required Long. The list item to be set.


 ListCount Property

ListCount Property

Returns the number of list items in a command bar combo box control. Read-only Long.


ListCount Property Example

This example checks the number of items in the combo box on the command bar named "Custom." If there aren’t three items in the list that the procedure produces, the example displays a message advising the user that the combo box may be damaged and asks the user to reinstall the application.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
With CommandBars("Custom").Controls(1)
    .AddItem "Get Stock Quote", 1
    .AddItem "View Chart", 2
    .AddItem "View Fundamentals", 3
    .Caption = "Stock Data"
    .DescriptionText = "View Data For Stock"
End With
If CommandBars("Custom").Controls(1).ListCount _
     <> 4 Then
MsgBox ("ComboBox appears to be damaged." & _
     " Please reinstall.")
End If


 ListHeaderCount Property

ListHeaderCount Property

Returns or sets the number of list items in a command bar combo box control that appears above the separator line. Read/write Long.

Note This property is read-only for built-in combo box controls.

Remarks

A ListHeaderCount property value of – 1 indicates that there's no separator line in the combo box control.


ListHeaderCount Property Example

This example adds a combo box control to the command bar named "Custom" and then adds two items to the combo box. The example uses the ListHeaderCount property to display a separator line between First Item and Second Item in the combo box. The example also sets the number of line items, the width of the combo box, and an empty default for the combo box.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls.Add(Type:=msoControlComboBox)
With myControl
    .AddItem Text:="First Item", Index:=1
    .AddItem Text:="Second Item", Index:=2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 1
End With


 ListIndex Property

ListIndex Property

Returns or sets the index number of the selected item in the list portion of the command bar combo box control. If nothing is selected in the list, this property returns zero. Read/write Long.

Note This property fails when applied to controls other than list controls.

Remarks

Setting the ListIndex property causes the specified control to select the given item and execute the appropriate action in the application.


ListIndex Property Example

This example uses the ListIndex property to determine the correct subroutine to run, based on the selection in the combo box on the command bar named “My Custom Bar.” Because the procedure uses ListIndex, the text in the combo box can be anything.

Sub processSelection()
Dim userChoice As Long
userChoice = CommandBars("My Custom Bar").Controls(1).ListIndex
    Select Case userChoice
        Case 1
            chartcourse
        Case 2
            displaygraph
        Case Else
            MsgBox ("Invalid choice. Please choose again.")
    End Select
End Sub


Location Property

Returns the location of the script anchor in the specified HTML document. Can be either of the following MsoScriptLocation constants: msoScriptLocationInBody or msoScriptLocationInHead. Read-only Long.

Remarks

Script tags in an HTML document can appear anywhere between the <HTML> tags in the document. In Microsoft Word, Excel, or PowerPoint, only the script anchors located between the <BODY> tags are visible. Additional HTML script that appears before or after the <BODY> tags is stored in but isn’t visible to the user.

The Scripts collection contains all of the script anchors that appear in the document, whether inside or outside of the main body of the document. Using the Location argument of the Add method, you can insert script anchors within the <HEAD> and <BODY> tags in the HTML document. You can also use the Location property to determine where a particular script anchor is stored within the document.


Location Property Example

This example checks the Location property of the first script in worksheet one in the active workbook and displays the location in a message box.

If ActiveWorkbook.Worksheets(1).Scripts(1).Location = 1 Then
    MsgBox "The script in located in the header."
End If
If ActiveWorkbook.Worksheets(1).Scripts(1).Location = 2 Then
    MsgBox "The script in located in the body of the worksheet."
End If


LookIn Property

Returns or sets the folder to be searched during the specified file search. Read/write String.


LookIn Property Example

This example searches the My Documents folders for all files that begin with "Cmd" and displays the name and location of each file that’s found.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "cmd*.*"
    If .Execute > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
        " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


MatchAllWordForms Property

True if the file search is expanded to include all forms of the specified word contained in the body of the file, or in the file's properties. Read/write Boolean.

Remarks

This property is available only if the file Mswds_en.lex has been installed and registered. Note that this file isn't installed as part of a Typical setup.


MatchAllWordForms Property Example

This example returns all files that contain the word "run," "running," "runs," or "ran" in the body of the file, or in the properties of the file. The TextOrProperty property sets the word to be matched, and limits the search to either the body of the file or the file properties.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .TextOrProperty = "run"
    .MatchAllWordForms = True
    .FileType = msoFileTypeAllFiles
End With


MatchTextExactly Property

True if the specified file search will find only files whose body text or file properties contain the exact word or phrase that you've specified. Read/write Boolean.


MatchTextExactly Property Example

This example searches the C:\My Documents folder and returns all files that contain the word "Run" either in the body text or in the file properties.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .TextOrProperty = "Run"
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
End With


 MenuAnimationStyle Property

MenuAnimationStyle Property

Returns or sets the way a command bar is animated. Can be one of the following MsoMenuAnimation constants: msoMenuAnimationNone, msoMenuAnimationRandom, msoMenuAnimationUnfold, or msoMenuAnimationSlide. Read/write.


MenuAnimationStyle Property Example

This example sets options for all command bars in Microsoft Office.

With CommandBars
    .LargeButtons = True
    .DisplayTooltips = True
    .DisplayKeysInTooltips = True
    .MenuAnimationStyle = msoMenuAnimationUnfold
End With


Mode Property

Returns or sets the modal behavior of the Office Assistant balloon. Can be one of the following MsoModeType constants: msoModeAutoDown, msoModeModal, or msoModeModeless. When you create a Balloon object, this property is initially set to msoModeModal. Read/write Long.

Remarks

If the Mode property for a balloon is set to msoModeModeless, the user can work in the application while the balloon is visible. If the property is set to msoModeModal, the user must dismiss the balloon before continuing to work in the application. If the property is set to msoModeAutoDown, the balloon is dismissed when the user clicks anywhere on the screen.

If the Mode property for a balloon is set to msoModeModeless and a value for the Callback property is not supplied, an error occurs. The Close method can only be used in the procedure specified by the Callback property when the Mode property is set to msoModeModeless.


Mode Property Example

This example creates a balloon with an alert icon that instructs the user to select a printer. Because the balloon is modeless, the user has access to printer commands while the balloon is visible. When the user clicks the OK button, the procedure specified in the Callback property is run.

With Assistant.NewBalloon
    .Heading = "Select A Printer"
    .Text = "You must select a printer before printing."
    .Icon = msoIconAlert
    .CheckBoxes(1).Text = "Local printer"
    .CheckBoxes(2).Text = "Network printer"
    .Mode = msoModeModeless
    .Callback = "ProcessPrinter"
    .Show
End With


MouseTips Property

True if the Office Assistant provides suggestions for using the mouse effectively. Read/write Boolean.

Remarks

The MouseTips property corresponds to the Using the mouse more effectively option under Show tips about on the Options tab in the Office Assistant dialog box.


MouseTips Property Example

This example sets the Office Assistant to provide suggestions for using the mouse effectively.

Assistant.MouseTips = True


MoveWhenInTheWay Property

True if the Office Assistant window automatically moves when it's in the way of the user's work area. For example, the Assistant will move if it's in the way of dragging or dropping or in the way of keystroke entries. Read/write Boolean.

Remarks

The default value is True. The MoveWhenInTheWay property corresponds to the Move when in the way option in the Use the Office Assistant section on the Options tab in the Office Assistant dialog box.


MoveWhenInTheWay Property Example

This example displays the Office Assistant in a specific location and it sets several options before making the Assistant visible and active.

With Assistant
    .On = True
    .Visible = True
    .Left = 400
    If Not MoveWhenInTheWay Then MoveWhenInTheWay = True
    .Animation = msoAnimationGetAttentionMajor
End With


 Name Property

Name Property

Returns or sets the name of the specified object. Read/write String for the CommandBar and DocumentProperty objects; read-only String for all other objects.

Remarks

The local name of a built-in command bar is displayed in the title bar (when the command bar isn't docked) and in the list of available command bars — wherever that list is displayed in the container application.

For a built-in command bar, the Name property returns the command bar's U.S. English name. Use the NameLocal property to return the localized name.

If you change the value of the LocalName property for a custom command bar, the value of Name changes as well, and vice versa.


 NameLocal Property

NameLocal Property

Returns the name of a built-in command bar as it's displayed in the language version of the container application, or returns or sets the name of a custom command bar. Read/write String.

Note If you attempt to set this property for a built-in command bar, an error occurs.

Remarks

The local name of a built-in command bar is displayed in the title bar (when the command bar isn't docked) and in the list of available command bars, wherever that list is displayed in the container application.

If you change the value of the LocalName property for a custom command bar, the value of Name changes as well, and vice versa.


NameLocal Property Example

This example displays the name and localized name of the first command bar in the container application.

With CommandBars(1)
    MsgBox "The name of the command bar is " & .Name
    MsgBox "The localized name of the command bar is " & .NameLocal
End With


NewBalloon Property

Creates an Office Assistant balloon. Returns a Balloon object. Read-only.


NewBalloon Property Example

This example creates a balloon with a heading, text, and three region choices, and then displays it.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select one or more regions"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Show
End With


Object Property

Sets or returns the object that is the basis for the specified COMAddIn object. Read/write Object.

Remarks

This property is primarily used for enabling one COMAddIn to communicate with another COMAddIn.


Object Property Example

The following example returns the object associated with the COM add in msodraa9.ShapeSelect.

Dim objBaseObject As Object
Set objBaseObject = _
    Application.COMAddIns.Item("msodraa9.ShapeSelect"). _
      Object


 OLEMenuGroup Property

OLEMenuGroup Property

Returns or sets the menu group that the specified command bar pop-up control belongs to when the menu groups of the OLE server are merged with the menu groups of an OLE client (that is, when an object of the container application type is embedded in another application). Can be one of the following MsoOLEMenuGroup constants: msoOleMenuGroupNone, msoOleMenuGroupFile, msoOleMenuGroupEdit, msoOleMenuGroupContainer, msoOleMenuGroupObject, msoOleMenuGroupWindow, or msoOleMenuGroupHelp. Read/write Long.

Note This property is read-only for built-in controls.

Remarks

This property is intended to allow add-in applications to specify how their command bar controls will be represented in the Office application. If either the container or the server does not implement command bars, normal OLE menu merging will occur: the menu bar will be merged, as well as all the toolbars from the server, and none of the toolbars from the container. This property is relevant only for pop-up controls on the menu bar because menus are merged on the basis of their menu group category.

If both of the merging applications implement command bars, command bar controls are merged according to the OLEUsage property.


OLEMenuGroup Property Example

This example checks the OLEMenuGroup property of a new custom pop-up control on the command bar named “Custom” and sets the property to msoOLEMenuGroupNone.

Set myControl = CommandBars("Custom").Controls _
    .Add(Type:=msoControlPopup,Temporary:=False)
myControl.OLEMenuGroup = msoOLEMenuGroupNone


 OLEUsage Property

OLEUsage Property

Returns or sets the OLE client and OLE server roles in which a command bar control will be used when two Microsoft Office applications are merged. Can be one of the following MsoControlOLEUsage constants: msoControlOLEUsageNeither, msoControlOLEUsageServer, msoControlOLEUsageClient, or msoControlOLEUsageBoth. Read/write Long.

Remarks

This property is intended to allow you to specify how individual add-in applications' command bar controls will be represented in one Office application when it is merged with another Office application. If both the client and server implement command bars, the command bar controls are embedded in the client control by control. Custom controls marked as client-only (or neither client nor server) are dropped from the server, and controls marked as server-only (or neither server nor client) are dropped from the client. The remaining controls are merged.

If one of the merging applications isn't an Office application, normal OLE menu merging is used, which is controlled by the OLEMenuGroup property.


OLEUsage Property Example

This example adds a new button to the command bar named Tools, and sets its OLEUsage property.

Set myControl = CommandBars("Tools").Controls _
    .Add(Type:=msoControlButton,Temporary:=True)
myControl.OLEUsage = msoControlOLEUsageNeither


On Property

True if the Office Assistant is enabled. Read/write Boolean.


 OnAction Property

OnAction Property

Returns or sets the name of a Visual Basic procedure that will run when the user clicks or changes the value of a command bar control. Read/write String.

Note The container application determines whether the value is a valid macro name.


OnAction Property Example

This example adds a command bar control to the command bar named "Custom". The procedure named "MySub" will run each time the control is clicked.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls _
    .Add(Type:=msocontrolButton)
With myControl
    .FaceId = 2
    .OnAction = "MySub"
End With
myBar.Visible = True

This example adds a command bar control to the command bar named "Custom". The COM add in named "CallFinanceAddIn" will run each time the control is clicked.

Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls _
    .Add(Type:=msocontrolButton)
With myControl
    .FaceId = 2
    .OnAction = "!<FinanceAddIn>"
End With
myBar.Visible = True


Parameter Property

Returns or sets a string that an application can use to execute a command. Read/write String.

Remarks

If the specified parameter is set for a built-in control, the application can modify its default behavior if it can parse and use the new value. If the parameter is set for custom controls, it can be used to send information to Visual Basic procedures, or it can be used to hold information about the control (similar to a second Tag property value).


Parameter Property Example

This example assigns a new parameter to a control and sets the focus to the new button.

Set myControl = CommandBars("Custom").Controls(4)
With myControl
    .Copy , 1
    .Parameter = "2"
    .SetFocus
End With


Parent Property

Returns the Parent object for the specified object. Read-only.


Parent Property Example

This example displays the name of the parent object for a document property. You must pass a valid DocumentProperty object to the procedure.

Sub DisplayParent(dp as DocumentProperty)
    MsgBox dp.Parent.Name
End Sub


 Position Property

Position Property

Returns or sets the position of a command bar. Can be one of the following MsoBarPosition constants: msoBarLeft, msoBarTop, msoBarRight, msoBarBottom, msoBarFloating, msoBarPopup, or msoBarMenuBar. Read/write Long.


Position Property Example

This example steps through the collection of command bars, docking the custom command bars at the bottom of the application window and docking the built-in command bars at the top of the window.

For Each bar In CommandBars
    If bar.Visible = True Then
        If bar.BuiltIn Then
            bar.Position = msoBarTop
         Else
            bar.Position = msoBarBottom
        End If
    End If
Next


 Priority Property

Priority Property

Returns or sets the priority of a command bar control. A control's priority determines whether the control can be dropped from a docked command bar if the command bar controls can't fit in a single row. Read/write Long.

Remarks

Valid priority numbers are 0 (zero) through 7. A priority of 1 means that the control cannot be deleted from a toolbar. Other priority values are ignored.

The Priority property is not used by command bar controls that are menu items.


Priority Property Example

This example moves a control and assigns it a priority of 5 so that it will likely be dropped from the command bar if the controls don't all fit in one row.

Set allcontrols = CommandBars("Custom").Controls
For Each ctrl In allControls
    If ctrl.Type = msoControlComboBox Then
        With ctrl
            .Move Before:=7
            .Tag = "Selection box"
            .Priority = 5
        End With
    Exit For
End If
Next


Private Property

Returns or sets an integer that identifies the Office Assistant balloon that initiated the callback procedure. Read/write Long.

Remarks

This property is helpful if you run the same callback procedure from more than one balloon.


Private Property Example

This example identifies the Office Assistant balloon by setting the Private property to 129.

Set printerOrientation = Assistant.NewBalloon
With printerOrientation     .Heading = " Print portrait or landscape?"
     .Text = "Click OK when you've selected the " & _
        "printer orientation."
    .Labels(1).Text = "Portrait"
    .Labels(2).Text = "Landscape"
    .BalloonType = msoBalloonTypeButtons
    .Mode = msoModeModeless
    .Button = msoButtonSetOK
    .Private = 129
    .Callback = "PortraitOrLandscape "
    .Show
End With


ProgId Property

Returns the programmatic identifier (ProgID) for the specified COMAddIn object. Read-only String.


ProgId Property Example

The following example displays the ProgID and GUID for COM add-in one in a message box.

MsgBox "My ProgID is " & _
    Application.COMAddIns(1).ProgID & _
    " and my GUID is " & _
    Application.COMAddIns(1).Guid


PropertyTests Property

Returns the PropertyTests collection that represents all the search criteria for a file search. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.


PropertyTests Property Example

This example displays all the search criteria for the first property test in the collection.

With Application.FileSearch.PropertyTests(1)
myString = "This is the search criteria: " _
    & " The name is: " & .Name & ". The condition is: " _
    & .Condition
If .Value <> "" Then
    myString = myString & ". The value is: " & .Value
    If .SecondValue <> "" Then
        myString = myString _
            & ". The second value is: " _
            & .SecondValue & ", and the connector is" _
            & .Connector
    End If
End If
MsgBox myString
End With


ProportionalFont Property

Sets or returns the proportional font setting in the host application. Read/write String.

Remarks

When you set the ProportionalFont property, the host application does not check the value for validity.


ProportionalFontSize Property

Sets or returns the proportional font size setting in the host application, in points. Read/write Single.

Remarks

When you set the ProportionalFontSize property, the host application does not check the value for validity. If you enter an invalid value, such as a nonnumber, the host application sets the size to 0 points. You can enter half-point sizes; if you enter other fractional point sizes, they are rounded up or down to the nearest half-point.


ProportionalFontSize Property Example

This example sets the proportional font and proportional font size for the English/Western European/Other Latin Script character set in the active application.

Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.ProportionalFont = "Tahoma"
Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.ProportionalFontSize = 14.5


 Protection Property

Protection Property

Returns or sets the way a command bar is protected from user customization. Can be one or more of the following MsoBarProtection constants: msoBarNoProtection, msoBarNoCustomize, msoBarNoResize, msoBarNoMove, msoBarNoChangeVisible, msoBarNoChangeDock, msoBarNoVerticalDock, or msoBarNoHorizontalDock. Read/write Long.

Remarks

Using the constant msoBarNoCustomize prevents users from accessing the Add or Remove Buttons menu (this menu enables users to customize a toolbar).


Protection Property Example

This example steps through the collection of command bars to find the command bar named "Forms." If this command bar is found, it's docking state is protected and it's made visible.

foundFlag = False
For i = 1 To CommandBars.Count
    If CommandBars(i).Name = "Forms" Then
            CommandBars(i).Protection = msoBarNoChangeDock
            CommandBars(i).Visible = True
            foundFlag = True
    End If
Next
If Not foundFlag Then
    MsgBox "'Forms' command bar is not in the collection."
End If


Reduced Property

True if the Office Assistant window appears in its smaller size. Read/write Boolean.

Remarks

This property is not used in Office 2000.


Reduced Property Example

This example displays the Office Assistant in a specific location and it sets several options before making the Assistant visible.

With Assistant
    .Reduced = True
    .Left = 400
    .MoveWhenInTheWay = True
    .TipOfDay = True
    .Visible = True
    .Animation = msoAnimationGreeting
End With


 RowIndex Property

RowIndex Property

Returns or sets the docking order of a command bar in relation to other command bars in the same docking area. Can be an integer greater than zero, or either of the following MsoBarRow constants: msoBarRowFirst or msoBarRowLast. Read/write Long.

Remarks

Several command bars can share the same row index, and command bars with lower numbers are docked first. If two or more command bars share the same row index, the command bar most recently assigned will be displayed first in its group.


RowIndex Property Example

This example adjusts the position of the command bar named "Custom" by moving it to the left 110 pixels more than the default, and it makes this command bar the first to be docked by changing its row index to msoBarRowFirst.

Set myBar = CommandBars("Custom")
With myBar
    .RowIndex = msoBarRowFirst
    .Left = 140
End With


ScriptText Property

Sets or returns the text contained in a block of script. Read/write String.

Remarks

The Microsoft Office host application doesn’t check the syntax of the script. The ScriptText property is the default property for the Script object.


ScriptText Property Example

This example sets the text of the first script in worksheet one in the active workbook.

ActiveWorkbook.Worksheets(1).Scripts(1).ScriptText = _
    "MsgBox ""New ScriptText"""


SearchSubFolders Property

True if the search includes all the subfolders in the folder specified by the LookIn property. Read/write Boolean.


SearchSubFolders Property Example

This example searches the My Documents folder and all of its subfolders for all files whose names begin with "Cmd." The example also displays the name and location of each file that's found.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .FileName = "cmd*"
    If .Execute() > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
         " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With


SearchWhenProgramming Property

True if the Office Assistant displays application and programming Help while the user is working in Visual Basic. Read/write Boolean.

Remarks

The default value is False. SearchWhenProgramming property corresponds to the Search for both product and programming help when programming option in the Use the Office Assistant section on the Options tab in the Office Assistant dialog box.


SearchWhenProgramming Property Example

This example allows the user to search both application and programming help while working in Visual Basic.

Assistant.SearchWhenProgramming = True


SecondValue Property

Returns an optional second value property test (as in a range) for the file search. Read-only Variant.

Remarks

This property is intended to be used to specify a range, and it can only be used with the MsoCondition constant msoConditionAnyTimeBetween or msoConditionAnyNumberBetween.


SecondValue Property Example

This example displays the second value of the search criteria (if it exists) in a dialog box. If the second value doesn't exist, the example displays another message.

With Application.FileSearch.PropertyTests(1)
If .SecondValue = "" Then
   MsgBox "You haven't specified a second value."
Else
    MsgBox "The second value you've set is: " _
    & .SecondValue
End If
End With


Shape Property

Returns a Shape object or InlineShape object, depending on the Microsoft Office host application. Read-only Object.

Remarks

The Shape property returns a Shape object in Microsoft Excel and PowerPoint. In Word, the Shape property returns a Shape object if the script anchor is floating; if it’s an inline anchor, however, this property returns an InlineShape object.


Shape Property Example

This example gets the shape associated with the first script in the Scripts collection and deletes it from worksheet one in the active workbook.

Dim objScriptShape As Object

Set objScriptShape = _
    ActiveWorkbook.Worksheets(1).Scripts(1).Shape
ObjScriptShape.Delete


 ShortcutText Property

ShortcutText Property

Returns or sets the shortcut key text displayed next to a button control when the button appears on a menu, submenu, or shortcut menu. Read/write String.

Remarks

You can set this property only for command bar buttons that contain an OnAction macro.


ShortcutText Property Example

This example displays the shortcut text for the Open command (File menu) on the Microsoft Excel Worksheet menu bar in a message box.

MsgBox (CommandBars("Worksheet Menu Bar"). _
    Controls("File").Controls("New...).ShortcutText)


Sounds Property

True if the Office Assistant produces the sounds that correspond to animations. Read/write Boolean.

Remarks

The default value is True. The Sounds property corresponds to the Make sounds option under Use the Office Assistant on the Options tab in the Office Assistant dialog box. If a sound card is not installed, this property has no effect.


Sounds Property Example

This example displays and animates the Office Assistant and allows sound.

With Assistant
    .Visible = True
    .On = True
    If Not Sounds Then Sounds = True
    .Animation = msoAnimationGreeting
End With


 State Property

State Property

Returns or sets the appearance of a command bar button control. Can be one of the following MsoButtonState constants: msoButtonUp, msoButtonDown, or msoButtonMixed. Read/write Long.


State Property Example

This example creates a command bar named “Custom” and adds two blank buttons to it. The example then sets the button on the left to msoButtonUp and sets the button on the right to msoButtonDown.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlButton, ID:=1
    .Controls.Add Type:=msoControlButton, ID:=1
    .Visible = True
End With
Set myControl1 = CommandBars("Custom").Controls(1)
myControl1.State = msoButtonUp
Set myControl2 = CommandBars("Custom").Controls(2)
myControl2.State = msoButtonDown


 Style Property

Style Property

Use with the CommandBarButton object: Returns or sets the way a command bar button control is displayed. Can be one of the following MsoButtonStyle constants: msoButtonAutomatic, msoButtonIcon, msoButtonCaption, msoButtonIconAndCaption, msoButtonIconAndCaptionBelow, msoButtonIconAndWrapCaption, msoButtonIconAndWrapCaptionBelow, or msoButtonWrapCaption. Read/write Long.

Used with the CommandBarComboBox object: Returns or sets the way a command bar combo box control is displayed. Can be either of the following MsoComboStyle constants: msoComboLabel or msoComboNormal. Read/write Long.


Style Property Example

This example creates a shortcut menu containing a button control and a combo box control and sets the style of each.

Set myBar = CommandBars _
    .Add(Name:="Custom1", Position:=msoBarPopup, Temporary:=False)
With myBar
    .Controls.Add Type:=msoControlButton, Id:=3
    .Controls(1).Style = msoButtonCaption
    .Controls.Add Type:=msoControlComboBox
    With .Controls(2)
        .Style = msoComboLabel
        .AddItem "vanilla"
        .AddItem "chocolate"
        .AddItem "cookie dough"
    End With
End With
myBar.ShowPopup


 Tag Property

Tag Property

Returns or sets information about the command bar control, such as data that can be used as an argument in procedures, or information that identifies the control. Read/write String.


Tag Property Example

This example sets the tag for the button on the custom command bar to "Spelling Button" and displays the tag in a message box.

CommandBars("Custom").Controls(1).Tag = "Spelling Button"
MsgBox (CommandBars("Custom").Controls(1).Tag)


 Text Property

Text Property

CommandBarComboBox object: Returns or sets the text in the display or edit portion of the command bar combo box control. Read/write String.

BalloonLabel or BalloonCheckbox object: Returns or sets the text displayed next to a check box or label in the Office Assistant balloon. Read/write String.

Balloon object: Returns or sets the text displayed after the heading but before the labels or check boxes in the Office Assistant balloon. Read/write String.

HTMLProjectItem object: Returns or sets the HTML text in the HTML editor. Read/write String.

Remarks

For the Balloon, BalloonLabel, and BalloonCheckbox objects, you can specify that a particular graphic be displayed by using the following syntax: {type location sizing_factor}, where type is bmp (bitmap) or wmf (Windows metafile; location is the resource ID or the path and file name; and sizing_factor denotes the width of the .wmf file (sizing_factor is omitted for .bmp files).

The Balloon object also supports underlined text and text that has one of the 16 system palette colors applied to it. To display underlined text, use the syntax {ul} or {ul 1}; use {ul 0} to turn underlining off. To change the color of text, precede the text string with the character sequence {cf number}, where number is one of the system color numbers listed in the following table.

System color number | Color
0 | Black
1 | Dark red
2 | Dark green
3 | Dark yellow
4 | Dark blue
5 | Dark magenta
6 | Dark cyan
7 | Light gray
248 | Medium gray
249 | Red
250 | Green
251 | Yellow
252 | Blue
253 | Magenta
254 | Cyan
255 | White

If you specify a number other than one of the preceding system color numbers, the text in the Office Assistant balloon is black.


TextOrProperty Property

Returns or sets the word or phrase to be searched for, in either the body of a file or the file's properties, during the file search. The word or phrase can include the * (asterisk) or ? (question mark) wildcard character. Read/write String.

Remarks

Use the question mark wildcard character to match any single character. For example, type gr?y to find all files that contain at least one instance of either "gray" or "grey."

Use the asterisk wildcard character to match any number of characters. For example, type San* to return all files that contain at least one word that begins with "San."


TextOrProperty Property Example

This example searches the C:\My Documents folder and all of its subfolders and returns all files whose body text or file properties contain any words that begin with "San." The TextOrProperty property sets the word to be searched for and limits the search to either the body of the file or the file properties.

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\My Documents"
    .SearchSubFolders = True
    .TextOrProperty = "San*"
    .FileType = msoFileTypeAllFiles
End With


TipOfDay Property

True if the Office Assistant displays a special tip each time the Office application is opened. Read/write Boolean.

Remarks

The default value is False. TipOfDay property corresponds to the Show the Tip of the Day at startup option under Show tips about on the Options tab in the Office Assistant dialog box.


TipOfDay Property Example

This example displays the Office Assistant in a specific location and it sets several options before making the Assistant visible.

With Assistant
    .On = True
    .Visible = True
    .Left = 400
    .MoveWhenInTheWay = True
    If Not TipOfDay Then TipOfDay = True
    .Animation = msoAnimationGreeting
End With


TooltipText Property

Returns or sets the text displayed in a command bar control's ScreenTip. Read/write String.

Remarks

By default, the value of the Caption property is used as the ScreenTip.


TooltipText Property Example

This example adds a ScreenTip to the last control on the active menu bar.

Set myMenuBar = CommandBars.ActiveMenuBar
Set lastCtrl = myMenuBar _
   .Controls(myMenuBar.Controls.Count)
lastCtrl.BeginGroup = True
lastCtrl.TooltipText = "Click for help on UI feature"


 Top Property

Top Property

CommandBar or CommandBarControl object: Returns or sets the distance (in pixels) from the top edge of the specified command bar or command bar control to the top edge of the screen. For docked command bars, this property returns or sets the distance from the command bar to the top of the docking area. Read/write Long for CommandBar, read-only Long for CommandBarControl.

Assistant object: Sets or returns the distance (in points) from the top of the Office Assistant to the top edge of the screen. Read/write Integer.


Top Property Example

This example positions the upper-left corner of the floating command bar named "Custom" 140 pixels from the left edge of the screen and 100 pixels from the top of the screen.

Set myBar = CommandBars("Custom")
myBar.Position = msoBarFloating
With myBar
    .Left = 140
    .Top = 100
End With

This example moves the Office Assistant to another coordinate and sets its Top property for subsequent appearances.

With Assistant
    .On = True
    .Visible = True
    .Sounds = True
    .Animation = msoAnimationBeginSpeaking
End With
Assistant.Top = 100
MsgBox "Click OK to move the Assistant to a " & _
         "new location."
Assistant.Top = 500


 Type Property

Type Property

DocumentProperty object: Returns or sets the document property type. Can be one of the following MsoDocProperties constants: msoPropertyTypeBoolean, msoPropertyTypeDate, msoPropertyTypeFloat, msoPropertyTypeNumber, or msoPropertyTypeString. Read-only for built-in document properties; read/write for custom document properties.

CommandBar object: Returns the type of command bar. Can be one of the following MsoBarType constants: msoBarTypeNormal, msoBarTypeMenuBar, or msoBarTypePopup. Read-only Long.

CommandBarControl object: Returns the type of command bar control. Read-only Long.

Can be one of the MsoControlType constants listed in the following table.

Constant | Control type
msoControlActiveX | ActiveX control
msoControlButton | Example of msoControlButton constant
msoControlButtonDropdown | Example of msoControlButtonDropdown constant
msoControlButtonPopup | Example of msoControlButtonPopup constant
msoControlComboBox | Example of msoControlComboBox constant
msoControlCustom | Reserved for future use.
msoControlDropdown | Example of msoControlDropdown constant
msoControlEdit | Example of msoControlEdit constant
msoControlExpandingGrid | Example of msoControlExpandingGrid constant
msoControlGauge | Example of msoControlGauge constant
msoControlGenericDropdown | Reserved for future use.
msoControlGraphicCombo | Example of msoControlGraphicCombo constant
msoControlGraphicDropdown | Example of msoControlGraphicDropdown constant
msoControlGraphicPopup | Reserved for future use.
msoControlGrid | Example of msoControlGrid constant
msoControlLabel | Reserved for future use.
msoControlOCXDropDown | Example of msoControlOCXDropdown constant
msoControlPane | Pane control
msoControlPopup | Example of msoControlPopup constant
msoControlSplitButtonMRUPopup | Example of msoControlSplitButtonMRUPopup constant
msoControlSplitButtonPopup | Example of msoControlSplitButtonPopup constant
msoControlSplitDropdown | Example of msoControlSplitDropdown constant
msoControlSplitExpandingGrid | Reserved for future use.


Type Property Example

This example finds the first control on the command bar named “Custom”. Using the Type property, the example determines whether the control is a button. If the control is a button, the example copies the face of the Copy button (on the Standard toolbar) and then pastes it onto the control.

Set oldCtrl = CommandBars("Custom").Controls(1)
If oldCtrl.Type = 1 Then
    Set newCtrl = CommandBars.FindControl(Type:= _
        MsoControlButton, ID:= _
        CommandBars("Standard").Controls("Copy").ID)
    NewCtrl.CopyFace
    OldCtrl.PasteFace
End If

This example displays the name, type, and value of a document property. You must pass a valid DocumentProperty object to the procedure.

Sub DisplayPropertyInfo(dp As DocumentProperty)
    MsgBox "value = " & dp.Value & Chr(13) & _
        "type = " & dp.Type & Chr(13) & _
        "name = " & dp.Name
End Sub


Value Property

DocumentProperty object: Returns or sets the value of a document property. Read/write Variant.

PropertyTest object: Returns the value of a property test for a file search. Read-only Variant.

Remarks

If the container application doesn't define a value for one of the built-in document properties, reading the Value property for that document property causes an error.


Value Property Example

This example displays the name, type, and value of a document property. For the example to work, dp must be a valid DocumentProperty object.

Sub DisplayPropertyInfo(dp As DocumentProperty)
    MsgBox "value = " & dp.Value & Chr(13) & _
        "type = " & dp.Type & Chr(13) & _
        "name = " & dp.Name
End Sub

This example displays the value of the search criteria (if it exists) in a dialog box. If the second value doesn't exist, the example displays another message.

With Application.FileSearch.PropertyTests(1)
If .Value = "" Then
   MsgBox "You haven't specified a value."
Else
    MsgBox "The value you've set is: " _
    & .Value
End If
End With


 Visible Property

Visible Property

CommandBar and CommandBarControl object: True if a command bar or command bar control is visible. Read/write Boolean.

Assistant object: True if the Office Assistant is visible. Read/write Boolean.

Remarks

The Visible property for newly created custom command bars is False by default.

The Enabled property for a command bar must be set to True before the visible property is set to True.


Visible Property Example

This example steps through the collection of command bars to find the Forms command bar. If the Forms command bar is found, the example makes it visible and protects its docking state.

foundFlag = False
For Each cmdbar In CommandBars
    If cmdbar.Name = "Forms" Then
        cmdbar.Protection = msoBarNoChangeDock
        cmdbar.Visible = True
        foundFlag = True
    End If
Next
If Not foundFlag Then
    MsgBox "'Forms'command bar is not in the collection."
End If

This example makes the Office Assistant visible and sets its animation.

With Application.Assistant
    .Visible = True
    .Sounds = True
    .Animation = msoAnimationBeginSpeaking
End With


 Width Property

Width Property

Returns or sets the width (in pixels) of the specified command bar control. Read/write Long. For command bars, the Width property is read-only.


Width Property Example

This example adds a custom control to the command bar named "Custom". The example sets the height of the custom control to twice the height of the command bar and sets its width to 50 pixels. Notice how the command bar automatically resizes itself to accommodate the control.

Set myBar = CommandBars("Custom")
barHeight = myBar.Height
Set myControl = myBar.Controls _
    .Add(Type:=msoControlButton, _
    Id:= CommandBars("Standard").Controls("Save").Id, _
     Temporary:=True)
With myControl
    .Height = barHeight * 2
    .Width = 50
End With
myBar.Visible = True


New Events

New events in Microsoft Office are listed in the following table.

Event | Object
Change | CommandBarComboBox
Click | CommandBarButton
OnUpdate | CommandBars


Creating and Modifying Balloons

Use the Office Assistant balloon to provide information to your user. The information inside the balloon can be a simple message, a request for more information, or a list of choices for the user. Office Assistant balloons are created, displayed, closed, and changed at run time.

The following table contains the most commonly used properties and methods for changing either the appearance or function of a new or existing balloon. Balloons are displayed, or refreshed, when the Show method is used; therefore, changes you make to a balloon will appear the next time the Show method is used.

Property or method | Description
Heading | Specifies the bold text appearing at the top of the Office Assistant balloon.
Text | Specifies the text appearing in the body of the Office Assistant balloon. This text appears after the heading but before any check boxes, labels, or buttons.
Labels | Returns the collection of labels in the balloon. The format of the labels is determined by the BalloonType property. Labels appear after the balloon text. The list of labels can be numbered or bulleted, or a list of buttons. Unlike check boxes, the user's choice is registered as soon as a button is clicked.
CheckBoxes | Returns the collection of check boxes in the balloon. The user clicks the check box and clicks the appropriate button at the bottom of the balloon (for example, OK or Next) to register his or her choice.
Close | Closes and dismisses a modeless balloon, but doesn't release the object variable. The object variable assigned to the balloon is still valid — you can display it again, or you can modify it and display it later. You can use this method only on modeless balloons.
Show | Displays the balloon, and all the objects inside it, to the user. Use this method only for Balloon objects; use the Visible property for the Assistant object.

The following example creates a balloon that helps the user select a printer. The example provides a check box option for users who want to skip the information in the balloon.

Set bln = Assistant.NewBalloon
With bln
    .Heading = "Instructions for Choosing a Printer."
    .Text = "Click OK when you've chosen a printer."
    lblTxt = "From the File menu, choose Print."
    .Labels(1).Text = lblTxt
    .Labels(2).Text = "Click Setup."
    .Labels(3).Text = "Select the name of the printer."
    .CheckBoxes(1).Text = "Skip this information."
    .BalloonType = msoBalloonTypeNumbers
    .Mode = msoModeModal
    .Button = msoButtonSetOK
    .Show
End With

Creating balloons

To create a new balloon, use the NewBalloon property of the Assistant object. The new balloon will be blank. Use the Heading property to add a heading, and use the Text property to add text to the body of the balloon and then add controls, if needed. Finally, use the Show method to display the balloon. The Show method will show the balloon as it appears at that moment; therefore, it's important to use this method after setting all the other properties of the balloon. The following example creates a new balloon, sets the heading and body text, and creates three check box controls that the user can select.

With Assistant.NewBalloon
    .Button = msoButtonSetOkCancel
    .Heading = "Regional Sales Data"
    .Text = "Select a region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Show
End With

Managing multiple balloons

The Office Assistant does not have a Balloons collection. To manage multiple balloons, you can set a separate object variable for each balloon you create and refer to the variable as needed. Or you can create an array of Balloon object variables and assign a balloon to each one. The following example creates an array and adds three blank Balloon objects to the array.

Dim myBalloonArray(3) As Balloon

With Assistant
    For i = 1 To 3
        Set myBalloonArray(i) = .NewBalloon
    Next
End With


Getting Help on Macintosh Keywords

You have requested Help for a Visual Basic keyword used only on the Macintosh. For information about this keyword, consult the language reference Help included with Microsoft Office 98 Macintosh Edition.


Making Run-Time Modifications to Balloons

After you create a balloon for the Office Assistant, you can customize it by adding bitmaps, icons, or Windows metafiles to the balloon's heading or text. You can add controls such as check boxes or buttons to your balloon so that you can respond to your user when he or she clicks an item in the balloon. You can also use text attributes such as color and underlining to emphasize text elements in a balloon.

Adding icons and bitmaps to balloons

To customize your application, you can add icons and bitmaps to Office Assistant balloons. To add an icon, assign an MsoIconType constant to the Icon property of the Balloon object. To add a bitmap or a Windows metafile to the text in an Office Assistant balloon, specify the type, the location, and the sizing factor (if applicable) when you set the Text property of a heading, text, check box, or label. The following example inserts a Windows bitmap file into the text of a balloon.

myBmp = "{bmp c:\Win95\circles.gif}"
myText1 = "This is before the picture, "
myText2 = " and this is after the picture"
Set bln = Assistant.NewBalloon
With bln
    .Heading = "Instructions for Choosing a Bitmap."
    .Text = myText1 & myBmp & myText2
    .Show
End With

Adding controls to balloons

There are two types of controls you can add to a balloon: check boxes and buttons. There are five check boxes in the balloon when it's created; you can make any one of them visible by specifying text for the control. There are five label buttons in the balloon as well (if the balloon type is msoBalloonTypeButtons), and you can expose any label in the same way you would a check box. If you try to expose more than five check boxes or five label buttons in a balloon, an error occurs.

You can change the appearance of any control on a balloon by changing the control's Text property. You can change the functionality of a check box or a button in a balloon by specifying another procedure that will be run whenever the check box or button is selected (clicked).

The following example creates a balloon with a heading, text, and three region choices. When the user selects one or more check boxes and clicks OK, the example calls the appropriate procedure or procedures.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select your region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Button = msoButtonSetOkCancel
    .Show
If .CheckBoxes(1).Checked Then
        runregion1
    End If
    If .CheckBoxes(2).Checked Then
        runregion2
    End If
    If .CheckBoxes(3).Checked Then
        runregion3
    End If
End With

Adding color and underlining to text in balloons

There are two attributes you can add to text in a balloon: color and underlining. There are 16 supported system colors you can use to emphasize text with color. You also can change the appearance of text in a balloon by underlining the text. Text attributes are embedded in the text of the balloon and are surrounded by braces in the code. The following example creates a new Office Assistant balloon that contains underlined heading text, red text, and blue text that is also underlined.

With Assistant.NewBalloon
    .Heading = "Underlined {ul 1}Heading{ul 0}"
    .Text = "Some {cf 249}Red{cf 0} text and some " & _
    "underlined {cf 252}{ul 1}Blue{ul 0}{cf 0} text."
    .Show
End With


Returning an Object from a Collection

The Item property returns a single object from a collection. The following example sets the cmdbar variable to a CommandBar object that represents the first command bar in the CommandBars collection.

Set cmdbar = CommandBars.Item(1)

The Item property is the default property for most collections, so you can write the same statement more concisely by omitting the Item keyword.

Set cmdbar = CommandBars(1)

For more information about a specific collection, see the Help topic for the collection or the Item property for the collection.


Using the Office Assistant

The Office Assistant is usually displayed with its balloon, presenting messages and providing Help, as your user works in your application. However, the Office Assistant can also be helpful to your user without its message balloon. You can get your user's attention with the Assistant alone by setting its Animation property. You can use other properties of the Assistant object to customize the way standard Office Help is presented to your user.

All of the properties listed on the Options tab in the Office Assistant dialog box correspond to a property of the Assistant you can set at run time. The properties listed in the following table are commonly used to modify the Office Assistant.

Property | Description
Animation | Animates the Office Assistant. Some animations are continuous; others occur only once.
FileName | Specifies the full file name for the Office Assistant, with the .act file extension. For example, the file name for the Rocky Office Assistant is Rocky.acs.
Name | Returns the name of the Office Assistant. If you want to keep track of which Office Assistant the user selects, use this property.
Visible | Specifies whether the Assistant is visible to or hidden.

The following example selects Rocky as the Office Assistant, makes the Assistant active and visible, selects an animation, and sets several options.

With Assistant
    .On = True
    .FileName = "Rocky.acs"
    .Animation = msoAnimationBeginSpeaking
    .AssistWithHelp = True
    .GuessHelp = True
    .FeatureTips = False
    .Visible = True
End With

There are six different Office Assistant “characters” you can choose to install with Microsoft Office, but only one Assistant character can be active at any given time. You can let the user select the Assistant from the Office Assistant Gallery, or you can select an Assistant for the user programmatically. You cannot modify the installed Assistant character files, and you cannot create a character file to use in place of the files provided.


(Untitled)

Help Topic Not Available

The Help topic cannot be displayed because Microsoft Office Visual Basic Help cannot be found, was not installed, or was removed.

To install Microsoft Office Visual Basic Help

  1. In Control Panel, double-click Add/Remove Programs.

  2. On the Install/Uninstall tab, click the edition of Microsoft Office 2000 that's installed, and then click Add/Remove.

  3. Click Add or Remove Features, and then expand Office Tools in the list of features.

  4. Click the icon next to Visual Basic Help to view the installation choices.

  5. Click Run from My Computer or Run from Network, and then click Update Now.


Add Method (PropertyTests Collection)

Adds a PropertyTest object to the PropertyTests collection.

Syntax

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

expression 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).

Condition Required Variant. The condition of the search criteria. Can be one of the following MsoCondition constants:

msoConditionAnyNumberBetween

msoConditionAnytime

msoConditionAnytimeBetween

msoConditionAtLeast

msoConditionAtMost

msoConditionBeginsWith

msoConditionDoesNotEqual

msoConditionEndsWith

msoConditionEquals

msoConditionFileTypeAllFiles

msoConditionFileTypeBinders

msoConditionFileTypeDatabases

msoConditionFileTypeExcelWorkbooks

msoConditionFileTypeOfficeFiles

msoConditionFileTypePowerPointPresentations

msoConditionFileTypeTemplates

msoConditionFileTypeWordDocuments

msoConditionIncludes

msoConditionIncludesNearEachOther

msoConditionIncludesPhrase

 msoConditionInTheLast

msoConditionInTheNext

msoConditionIsExactly

msoConditionIsNo

msoConditionIsNot

msoConditionIsYes

msoConditionLastMonth

msoConditionLastWeek

msoConditionLessThan

msoConditionMoreThan

msoConditionNextMonth

msoConditionNextWeek

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.

Connector Optional Variant. Specifies the way two search criteria are combined. Can be either of the following MsoConnector constants: msoConnectorAnd or msoConnectorOr.


Add Method (PropertyTests Collection) Example

This example adds two property tests to the search criteria. The first test is that the files must be 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


Add Method (Scripts Collection)

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.

Syntax

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.

Location Optional Long. Specifies the location of the script anchor in a document. Can be either of the following MsoScriptLocation constants: msoScriptLocationInBody or msoScriptLocationInHead. The default value is msoScriptLocationInBody. If you’ve specified the Anchor argument, the Location argument isn’t used; the location of the Anchor argument determines the location of the script anchor.

Language Optional Long. Specifies the script language. Can be one of the following MsoScriptLanguage constants: msoScriptLanguageASP, msoScriptLanguageJava, msoScriptLanguageOther, or msoScriptLanguageVisualBasic. The default value (language) is msoScriptLanguageVisualBasic.

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 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 (Scripts Collection) Example

This example adds a new Script to the specified range on worksheet one in the active workbook.

Dim rngScriptAnchorRange As Range
Dim objNewScript As Script

Set rngScriptAnchorRange = ActiveWorkbook. _
    Worksheets(1).Range("B5")
Set objNewScript = ActiveWorkbook. _
    Worksheets(1).Scripts.Add(rngScriptAnchorRange, _
      msoScriptLocationInBody, _
      msoScriptLanguageVisualBasic, _
      "MyNewScript", , _
      "MsgBox (""Added Script object MyNewScript"")")


Clear Method Example

This example checks the number of items in the combo box control on the command bar named "Custom." If there are fewer than three items in the list in the combo box, the example clears the list, adds a new first item to the list, and then displays this new item as the default for the combo box control.

Set myBar = CommandBars("Custom Bar")
Set myControl = myBar.Controls _
    Type:=msoControlComboBox)
With myControl
    .AddItem "First Item", 1
    .AddItem "Second Item", 2
End With
If myControl.ListCount < 3 Then
    myControl.Clear
    myControl.AddItem Text:="New Item", Index:=1
End If


Copy Method Example

This example copies the first control from the command bar named "Standard" to the first control on the command bar named "Custom”.

Set myCustomBar = CommandBars("Custom")
Set myControl = CommandBars("Standard").Controls(1)
With myControl
    .Copy Bar:=myCustomBar, Before:=1
    .SetFocus
End With


FindControl Method Example

This example finds the first control on the command bar named “Custom”. If the control is a button, the example uses the FindControl method to find the Copy button (on the Standard toolbar) and then copies the face from the Copy button and pastes it onto the control.

Set oldCtrl = CommandBars("Custom").Controls(1)
If oldCtrl.Type = 1 Then
    Set newCtrl = CommandBars.FindControl(Type:= _
        MsoControlButton, ID:= _
        CommandBars("Standard").Controls("Copy").ID)
    NewCtrl.CopyFace
    OldCtrl.PasteFace
End If


Item Method (COMAddIns Object)

Returns a member of the COMAddIns collection. With the Item method, you can use either an ordinal value that returns the COM add-in at that position in the COMAddIns collection, or a String value that represents the ProgID of the specified COM add-in.

Syntax

expression.Item

expression Required. The COMAddIns collection.


Item Method (HTMLProjectItem Object)

Returns the HTMLProjectItem object that represents a particular project in the Microsoft Script Editor.

Syntax

expression.Item(Index)

expression Required. An HTMLProjectItems collection.

Index Required Variant. The name or index number of the HTML project item to be returned


Item Method (Script Object)

Returns a member of the Scripts collection. Accepts the index number or ID of the script you want the Microsoft Office application to return. The Item method is a Variant value that can accept either an ordinal number (index value), which returns the script stored at that position in the Scripts collection, or a string value that represents the name or ID of the script.

Syntax

expression.Item(Index)

expression Required. An expression that returns a Script object.

Index Required Variant. The ID or index number of the script to be returned.

Remarks

The Scripts collection contains all of the scripts in a given document, in source order (the order in which Script objects appear in the source file). Scripts are maintained in source order regardless of their location in the document—that is, whether they’re in the header or the body text.

You can use the Item method to access a script in the Scripts collection by using the ID of the <SCRIPT> tag. The ID attribute of the <SCRIPT> tag is identical to the Id property of the Script object. If there are duplicate or multiple IDs in the document and you use the Id property of a Script object to access a script by using the Item method, Office returns the first script that matches the ID; additional scripts with the same ID are ignored.

New script anchors added to the collection are appended to the end of the Scripts collection in the order in which they were added to the document. The script anchors remain in this order until the document is saved as HTML, closed, and then opened again in the host application. Following these steps causes the Scripts collection to be indexed in the order in which the script anchors appear in the document, which may be different than the order in which they were added to it. Therefore, you’re advised to use the Id property of the Script object, rather than the script’s position in the collection, to ensure positive identification of the script.


Remove Method Example

This example removes the first search criterion from the collection.

Application.FileSearch.PropertyTests.Remove(1)


Reset Method Example

This example uses the value of user to adjust the command bars according to the user level. If user is "Level 1," the command bar named "Custom" is displayed. If user is any other value, the built-in Visual Basic command bar is reset to its default state and the command bar named "Custom" is disabled.

Set myBar = CommandBars("Custom")
If user = "Level 1" Then
    myBar.Visible = True
Else
    CommandBars("Visual Basic").Reset
    myBar.Enabled = False
End If


Show Method Example

This example creates a balloon containing two BalloonLabel choices for setting printer orientation: Portrait and Landscape. The example uses the Show method in a Select Case statement to determine which orientation the user has chosen.

Set balNew = Assistant.NewBalloon
With balNew
    .Heading = "Please choose a printer orientation"
    .Labels(1).Text = "Portrait"
    .Labels(2).Text = "Landscape"
    .Button = msoButtonSetNone
End With
    Select Case balNew.Show
    Case 1
        ' Insert code to set printer to portrait.
    Case 2
        ' Insert code to set printer to landscape.
    End Select

This example creates a balloon containing three command buttons: Yes, No, and Cancel. The example uses the Show method in a Select Case statement to determine the return value of the button clicked by the user.

Set balNew = Assistant.NewBalloon
With balNew
    .Heading = "Are you sure you want to set the " & _
    "printer orientation to landscape?"
    .BalloonType = msoBalloonTypeButtons
    .Button = msoButtonSetYesNoCancel
End With
    Select Case balNew.Show
    Case -2
        returnValue = MsgBox("Operation canceled.", _
        vbOKOnly, "Printer Message")
    Case -3
        returnValue = MsgBox("Printer set to " & _
        "landscape.", vbOKOnly, "Printer Message")
    Case -4
        returnValue = MsgBox("Printer orientation not " & _
        "reset.", vbOKOnly, "Printer Message")
    End Select


AdaptiveMenu Property Example

This example sets the AdaptiveMenu property to False for the File menu in the Microsoft Office application you’re working in.

CommandBars("File").AdaptiveMenu = False


BuiltIn Property Example

This example deletes all custom command bars that aren't visible.

foundFlag = False
deletedBars = 0
For Each bar In CommandBars
    If (bar.BuiltIn = False) And (bar.Visible = False) Then
        bar.Delete
        foundFlag = True
        deletedBars = deletedBars + 1
    End If
Next
If Not foundFlag Then
    MsgBox "No command bars have been deleted."
Else
    MsgBox deletedBars & " custom command bar(s) deleted."
End If


Connect Property Example

The following example displays a message box that indicates whether COM add-in one is registered and currently connected.

If Application.COMAddIns(1).Connect Then
    MsgBox "The add-in is connected."
Else
    MsgBox "The add-in is not connected."
End If


Description Property Example

The following example displays the description text of the Microsoft Accessibility COM add in for drawing.

MsgBox "The description of this " & _
    "COMAddIn is """ & Application.COMAddIns. _
    Item("msodraa9.ShapeSelect"). _
    Description & """


FixedWidthFont Property Example

This example sets the fixed-width font and fixed-width font size for the English/Western European/Other Latin Script character set in the active application.

Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.FixedWidthFont = "System"
Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.FixedWidthFontSize = 12


 Id Property (CommandBarControl Object)

Id Property (CommandBarControl Object)

Returns the ID for a built-in command bar control. Read-only Long.

Remarks

A control's ID determines the built-in action for that control. The value of the Id property for all custom controls is 1.


Id Property (CommandBarControl Object) Example

This example changes the button face of the first control on the command bar named "Custom2" if the button's ID value is less than 25.

Set ctrl = CommandBars("Custom").Controls(1)
With ctrl
    If .Id < 25 Then
        .FaceId = 17
        .Tag = "Changed control"
    End If
End With

The following example changes the caption of every control on the toolbar named "Standard" to the current value of the Id property for that control.

For Each ctl In CommandBars("Standard").Controls
    ctl.Caption = CStr(ctl.Id)
Next ctl


Id Property (Script Object)

Sets or returns the ID of a Script object. Read/write String.

Remarks

The ID returned is the ID attribute of the <SCRIPT> tag in HTML. If there’s no ID attribute specified in the <SCRIPT> tag, the Id property returns an empty string.

Id 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.


Id Property (Script Object) Example

This example sets the Id property of the first script in worksheet one in the active workbook to a new value.

ActiveWorkbook.Worksheets(1).Scripts(1).ID = "UpdatedScriptName"


Language Property Example

This example checks the Language property to ensure that the first script in worksheet one in the active workbook is written in VBScript.

If ActiveWorkbook.Worksheets(1).Scripts(1).Language <> _
    2 Then
      MsgBox "Language is not set to VBScript."
End If


List Property Example

This example checks the fourth list item in the combo box control whose caption is "Stock Data" on the command bar named "Custom." If the item isn’t "View News," the example displays a message advising the user that the combo box may be damaged and asks the user to reinstall the application.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
With CommandBars("Custom").Controls(1)
    .AddItem "Get Stock Quote", 1
    .AddItem "View Chart", 2
    .AddItem "View Fundamentals", 3
    .AddItem "View News", 4
    .Caption = "Stock Data"
    .DescriptionText = "View Data For Stock"
End With
If CommandBars("Custom").Controls(1).List(4) _
     <> "View News" Then
MsgBox ("Stock Data appears to be damaged." & _
     " Please reinstall application.")
End If


Name Property Example

This example searches the collection of command bars for the command bar named "Custom." If this command bar is found, the example makes it visible.

foundFlag = False
For Each bar In CommandBars
    If bar.Name = "Custom" Then
        foundFlag = True
        bar.Visible = True
    End If
Next
If Not foundFlag Then
    MsgBox "'Custom' bar isn't in collection."
Else
    MsgBox "'Custom' bar is now visible."
End If

This example displays the name, type, and value of a document property. You must pass a valid DocumentProperty object to the procedure.

Sub DisplayPropertyInfo(dp As DocumentProperty)
    MsgBox "value = " & dp.Value & Chr(13) & _
        "type = " & dp.Type & Chr(13) & _
        "name = " & dp.Name
End Sub


On Property Example

This example disables the Office Assistant, displays a message box that asks the user whether the Assistant should be enabled, and enables the Assistant if the user clicks Yes. If the users enables the Assistant, the Assistant appears and performs the animation msoAnimationGreeting.

Assistant.On = False
If MsgBox("Enable Office Assistant?", _
    vbYesNo, "Assistant is Off") = vbYes Then
    Assistant.On = True
    Assistant.Visible = True
    Assistant.Animation = _
        msoAnimationGetAttentionMajor
End If


ProportionalFont Property Example

This example sets the proportional font and proportional font size for the English/Western European/Other Latin Script character set in the active application.

Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.ProportionalFont = "Tahoma"
Application.DefaultWebOptions. _
Fonts(msoCharacterSetEnglishWesternEuropeanOtherLatinScript) _
.ProportionalFontSize = 14.5


Text Property Example

This example creates a new command bar named "Custom" and adds to it a combo box that contains four list items. The example then uses the Text property to set Item 3 as the default list item.

Set myBar = CommandBars _
    .Add(Name:="Custom", Position:=msoBarTop, _
    Temporary:=True)
With myBar
    .Controls.Add Type:=msoControlComboBox, ID:=1
    .Visible = True
End With
Set testComboBox = CommandBars("Custom").Controls(1)
With testComboBox
    .AddItem "Item 1", 1
    .AddItem "Item 2", 2
    .AddItem "Item 3", 3
    .AddItem "Item 4", 4
    .Text = "Item 3"
End With

This example creates a new Office Assistant balloon with a heading, text, and three region choices. The example uses the Text property to provide a label for each check box.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select a region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Show
End With

This example creates a new Office Assistant balloon with a heading, text, and three region choices. The example uses the Text property to provide balloon-related instructions to the user.

With Assistant.NewBalloon
    .Heading = "Regional Sales Data"
    .Text = "Select a region"
    For i = 1 To 3
        .CheckBoxes(i).Text = "Region " & i
    Next
    .Show
End With

This example creates a new Office Assistant balloon that contains underlined heading text, red text, and blue text that is also underlined.

With Assistant.NewBalloon
    .Heading = "Underlined {ul 1}Heading{ul 0}"
    .Text = "Some {cf 249}Red{cf 0} text and some " & _
    "underlined {cf 252}{ul 1}Blue{ul 0}{cf 0} text."
    .Show
End With

This example creates a new Office Assistant balloon that contains a Windows metafile.

With Assistant.NewBalloon
    .Heading = "Underlined {ul 1}Heading{ul 0}"
    .Text ="{WMF ""C:\Favorites\MyPicture.WMF""}"
    .Show
End With


New Properties (Alphabetic List)

Properties that have been added to existing objects in Microsoft Office are listed in the following table (sorted alphabetically).

Property | Object
AdaptiveMenu | CommandBar
AdaptiveMenus | CommandBars
DisplayFonts | CommandBars
HyperlinkType | CommandBarButton
IsPriorityDropped | CommandBarButton
IsPriorityDropped | CommandBarComboBox
IsPriorityDropped | CommandBarControl
IsPriorityDropped | CommandBarPopup
On | Assistant