Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 33
نمايش فراداده

Hack 12 Hack the Office Assistant

Keep ClippitMicrosoft's annoying computer help characteron a short leash with the techniques shown in this hack.

Ironically, the Office Assistant can be one of the more difficult features to manage in Word. But the Assistant can also be a powerful way to deliver a message to the user of a macro. The following examples take sort of an aikido approach: turning the power of its irritation to a positive end.

2.11.1 Banishing the Assistant

Among the more common reactions to the Assistant are requests to get rid of the wretched thing, immediately and permanently. So for many users, including the following line of code in an AutoExec macro [Hack #60] is the quickest way to a Clippit-free life:

Assistant.On = False

2.11.2 Finding a Sympathetic Character

You can switch from one Office Assistant character to another even more easily via VBA than via the Office Assistant's interface. To change characters, use the Filename property of the Assistant object:

Assistant.Filename = "OffCat.acs"

The quickest way to run this one-liner is from the Immediate window of the Visual Basic Editor [Hack #2], as shown in Figure 2-33.

Figure 2-33. Changing the Assistant character from the Immediate window

The available Office Assistant characters depend on your version of Office and the characters installed. Check the C:\Program Files\Microsoft Office\<Version> folder for .acs files (Microsoft Agent Character files). The name of the last folder, <Version>, depends on the version of Office involvedfor example, OFFICE11 is typical for Office 2003.

Your selection may vary, but a list of the usual suspects for a typical installation follows:

F1.acs

CLIPPIT.acs

DOT.acs

ROCKY.acs

OFFCAT.acs

MNATURE.acs

LOGO.acs

2.11.3 Invoking Invisibility

The Office Assistant just lurks in the background until you make a mistake that triggers its appearance. You can toggle the Office Assistant's visibility by setting its Visible property to True or False:

Assistant.Visible = True

You'll need to make sure the Assistant is turned on (Assistant.On = True) before you make it visible. Making the Assistant visible doesn't automatically turn it on. Again, you can quickly make this change from the Immediate window, as described above.

2.11.4 Getting the User's Attention

The Office Assistant usually appears (if currently hidden) or plays an animation (if displayed, but ignored) to get your attention. To play an animation, use Assistant.Animation. You can select animationsmsoAnimationAppear, msoAnimationEmptyTrash, msoAnimationRestPose, and msoAnimationSearchingfrom the auto-complete list provided by the Visual Basic Editor.

The following code summons the Assistant for delivering an urgent message:

Assistant.Animation = msoAnimationGetAttentionMajor

2.11.5 Displaying Information and Presenting Choices

To display information and present choices to the user, you use a balloon from the Office Assistant.

The following code displays the Assistant as shown in Figure 2-34. By checking the state of the Assistant before displaying the message, the macro can decide whether or not to turn off the Assistant after it finishes.

Figure 2-34. Use the Office Assistant to present information and straightforward choices from within a macro

Sub OA_CheckForMktngTemplate( )
Dim sMarketingTemplate As String
Dim blnAssistantWasOn As Boolean
sMarketingTemplate = "Marketing.dot"
If ActiveDocument.AttachedTemplate = sMarketingTemplate Then Exit Sub
With Assistant
blnAssistantWasOn = .On
.On = True
.Visible = True
.Animation = msoAnimationGetAttentionMajor
With .NewBalloon
.Heading = "Attach Correct Template"
.Text = "This document doesn't use the new Marketing template."
.BalloonType = msoBalloonTypeBullets
.Labels(1).Text = "You must use the Marketing template"
.Labels(2).Text = "Press OK to attach now"
.Icon = msoIconAlertQuery
.Button = msoButtonSetOkCancel
If .Show = msoBalloonButtonOK Then
ActiveDocument.AttachedTemplate = sMarketingTemplate
End If
End With
.On = blnAssistantWasOn
End With
End Sub

You can display your message using a variety of balloons, icons, and buttons, as detailed in the following tables.

Table 2-1 lists the types of balloons you can display.

Table 2-1. The three types of Assistant balloons

Balloon type

Constant

Value

Balloon with buttons (default)

msoBalloonTypeButtons

0

Balloon with bullets

msoBalloonTypeBullets

1

Balloon with numbered list

msoBalloonTypeNumbers

2

To control the text that appears in the balloon, use the following properties:

Heading

Displays a heading at the top of the balloon. You can use only one heading.

Text

Displays a single paragraph of text.

Labels(n).Text

Displays a bulleted or numbered paragraph, depending on the balloon type.

Table 2-2 lists the six icons you can display with the balloon (you can also display no icon).

Table 2-2. The icon choices for the Assistant dialogs

Icon

Constant

Value

No icon (default)

msoIconNone

0

Alert

msoIconAlert

2

Tip

msoIconTip

3

Information

msoIconAlertInfo

4

Warning

msoIconAlertWarning

5

Question mark

msoIconAlertQuery

6

Critical problem

msoIconAlertCritical

7

Table 2-3 lists the various button options for dismissing the dialog.

Table 2-3. The button options for the Assistant dialogs

Buttons

Constant

Value

No buttons

msoButtonSetNone

0

OK

msoButtonSetOK

1

Cancel

msoButtonSetCancel

2

OK, Cancel

msoButtonSetOkCancel

3

Yes, No, Cancel

msoButtonSetYesNoCancel

4

Yes, No

msoButtonSetYesNo

5

Back, Close

msoButtonSetBackClose

6

Next, Close

msoButtonSetNextClose

7

Back, Next, Close

msoButtonSetBackNextClose

8

Retry, Cancel

msoButtonSetRetryCancel

9

Abort, Retry, Ignore

msoButtonSetAbortRetryIgnore

10

Search, Close

msoButtonSetSearchClose

11

Back, Next, Snooze

msoButtonSetBackNextSnooze

12

Guy Hart-Davis