VBA generates an error if you try to access an office assistant using the Application object's FileName property for an assistant that has not been installed.

To install an office assistant, select it using the Choose Assistant menu item as described earlier in this section. If the assistant is not installed, Microsoft Office prompts you to install it.

To display the Office assistant using VBA, you need to work with the Application object's Assistant property. The Assistant property returns an object of Assistant type. Once the Assistant object is returned, you can use its properties and methods as shown in the code example.

Private Sub cmdShowAssistant_Click() With Application.Assistant .On = True

.FileName = "F1.ACS"

.Animation = msoAnimationGestureDown

.Visible = True

End With

End Sub

In the preceding code example, I've used a minimal number of Assistant object properties to display the character. In short, the On property enables and disables the assistant, the FileName property takes a string which identifies the assistant character to be displayed, and the Visible property hides or shows the assistant character.

There are more than 30 different animations that can be assigned to the Animation property:

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

Note that not all animations produce the desired animation (that depends on the selected character) and that different animations produce the same action.

To further demonstrate the Assistant object, consider the following program code. It uses form controls to show, hide, and animate Office assistants using VBA. Output is seen in Figure 11.3.

Using VBA to manage the Office assistant.

Using VBA to manage the Office assistant.

Private Sub cmdShowAssistant_Click()

If cmdShowAssistant.Caption = "Show Assistant" Then

With Application.Assistant

.FileName = "F1.ACS"

.Animation = msoAnimationGestureDown

.Visible = True

End With cmdShowAssistant.Caption = "Hide Assistant" Else

With Application.Assistant

.Visible = False End With cmdShowAssistant.Caption = "Show Assistant" End If End Sub

Private Sub optCheckingSomething_GotFocus()

With Application.Assistant

.Animation = msoAnimationCheckingSomething End With End Sub

Private Sub optGetTechy_GotFocus() With Application.Assistant

.Animation = msoAnimationGetTechy End With End Sub

Private Sub optListenToComputer_GotFocus() With Application.Assistant

.Animation = msoAnimationListensToComputer End With End Sub

Private Sub optSearching_GotFocus() With Application.Assistant

.Animation = msoAnimationSearching End With End Sub

Once the Assistant object is displayed in an Office application (Access, for example), the user can click it to use the assistant's help and search features or right-click the assistant character to display character options.

0 0

Post a comment