How trigger VBScript events in VBA ?

  • Thread starter Thread starter NilovSerge
  • Start date Start date
N

NilovSerge

Hallo!
1 I am working in OutLook with VBA. I can work only with events o
Application Object( ItemSend,NewMail,
StartUp,OptionsPagesAdd,Quit,Reminder ). In help(Microsoft OutLoo
Visual Basic Reference) I read:
Open Event Example
This VBScript example uses the Open event to display the "All Fields
page every time the item is opened.
Function Item_Open()
Item.GetInspector.SetCurrentFormPage "All Fields"
End Function

But I never get this event! What is VBScript ? How it differes fro
VBA? Do I need some
installation of Visual Basic? When and how it's events are triggered
For a example I need to catch the
event when a mailItem is Opened in Inspector...

Also I tried so :
Dim myOlApp As New Outlook.Application
Public WithEvents myOlItems As Outlook.Items
...
and create event
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
MsgBox ("myOlItems_ItemAdd")
End Sub
And this event never triggered! What is wrong?

2 I need create button by clicking open Address Book and chosen mail
set to my User Field. Is it
possible
 
VBScript is the language used for coding custom Outlook forms. You can also
use the Open event in VB/VBA by instantiating the MailItem whose events you
want to track. As a practical matter, this may mean that you need to
maintain a wrapper collection of MailItem objects. If, however, you were
looking at the event only to handle some initialization, you may also be
able to accomplish that with the Inspectors.NewInspector event.

As for your ItemAdd event, I don't see that you instantiated myOlItems
anywhere. See http://www.slipstick.com/dev/code/quarexe.htm for sample code.

See http://www.slipstick.com/dev/code/selectnames.htm for code to display
and use the results from the address book.
 
Thank you very much! ItemAdd event working!
1 But with resulting from the address book I had a problem
I used code from the example
...
Const cdoE_USER_CANCEL = &H80040113 ' start CDO session
Set objSession = CreateObject("MAPI.Session") '
' and Got error message "ActiveX component can't create object"
objSession.Logon , , False, False
...
In Tools/References I checked "Microsoft CDO for Windows 2000 Library"
Or I also need add some more libraries?
2 I need make some task when a user opens mail from a folder.
But event Open is not triggered! How can I "maintain a wrappe
collection of MailItem objects" ? Please, send me link for example!
I tried so:
' declaration
Public WithEvents myMailItems As Outlook.MailItem


Private Sub Application_Startup()
...
Set myMailItems = myOlApp.CreateItem(olMailItem) ' or that is wrong
How is wright?
...


' In toolbar appears object myMailItems and I can add events fo
myMailItems:
Private Sub myMailItems_Open(Cancel As Boolean)
MsgBox ("myMailItems_Open") ' this message never appears !
End Sub
What is wrong?
 
1) The library you need to use is CDO 1.21. CDO for Windows is totally
unrelated.

2) Study the Items Command Bar sample from http://www.microeye.com, which
demonstrates a wrapper class for Explorer objects. One for MailItem objects
would work similarly. You can use the NewInspector event to detect when the
user opens a MailItem. Your code below only instantiates a single new
message.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top