Article ID: 173690
Article Last Modified on 2/21/2005
Msgbox Assistant.VisibleHowever, Office Assistant properties cannot be changed or set, and methods may not be executed from within Visual Basic or any other development environment without a reference to an active Office application object. For example, executing the following line causes the error described above:
Assistant.Visible = TrueTo programmatically manipulate the Microsoft Office Assistants from within Visual Basic, you must create a reference to an active Office application object, such as "Access.Application," from which you can manipulate the Assistant.
Option Explicit
#Const OfficeAppObject = "Microsoft Access" 'Or "Microsoft Word" or
' "Microsoft Excel" or "Microsoft PowerPoint"
'Due to limitations in the Microsoft Outlook object model, you
'currently cannot manipulate the Office Assistant using a Microsoft
'Outlook object.
#If OfficeAppObject = "Microsoft Access" Then
'Establish a reference to "Microsoft Access 8.0 Object Library"
Dim objOffice As New Access.Application
#ElseIf OfficeAppObject = "Microsoft Word" Then
'Establish a reference to "Microsoft Word 8.0 Object Library"
Dim objOffice As New Word.Application
#ElseIf OfficeAppObject = "Microsoft Excel" Then
'Establish a reference to "Microsoft Excel 8.0 Object Library"
Dim objOffice As New Excel.Application
#ElseIf OfficeAppObject = "Microsoft PowerPoint" Then
'Establish a reference to "Microsoft PowerPoint 8.0 Object
'Library". NOTE: With this example, PowerPoint will become active
'and visible when executed.
Dim objOffice As New PowerPoint.Application
#Else
'If OfficeAppObject is NOT one of the four above items, a compiler
'error will occur!
#End If
Private Sub Timer1_Timer()
Dim bAssistantVisibility As Boolean
Dim msg As String
Dim iChoice As Integer
With objOffice.Assistant
bAssistantVisibility = .Visible
msg = "The Office Assistant Visible Property is set to" _
& Str$(bAssistantVisibility) & "." & vbCrLf & vbCrLf _
& "Do you want to see some Office Assistant Animation?"
iChoice = MsgBox(msg, vbYesNo, .Name)
Select Case iChoice
Case vbYes
#If OfficeAppObject = "Microsoft Access" Then
AppActivate "Microsoft Access", False
.Visible = True
#ElseIf OfficeAppObject = "Microsoft Word" Then
objOffice.WindowState = wdWindowStateMinimize
objOffice.Activate
#ElseIf OfficeAppObject = "Microsoft Excel" Then
objOffice.WindowState = xlMinimized
objOffice.Visible = True
.Visible = True
#ElseIf OfficeAppObject = "Microsoft PowerPoint" Then
objOffice.Activate
.Visible = True
#End If
Call subAnimation
Case vbNo
#If OfficeAppObject <> "Microsoft Access" Then
objOffice.Quit
#End If
Set objOffice = Nothing
End
End Select
End With
End Sub
Private Sub subAnimation()
With objOffice.Assistant
Select Case Int((8 * Rnd) + 1)
Case 1: .Animation = msoAnimationCheckingSomething
Case 2: .Animation = msoAnimationGetTechy
Case 3: .Animation = msoAnimationSearching
Case 4: .Animation = msoAnimationWorkingAtSomething
Case 5: .Animation = msoAnimationGetArtsy
Case 6: .Animation = msoAnimationSaving
Case 7: .Animation = msoAnimationThinking
Case 8: .Animation = msoAnimationWritingNotingSomething
Case Else: MsgBox "Random number generator error.", _
vbExclamation, "When I get 64"
End Select
End With
End Sub
Keywords: kbhowto kbautomation KB173690