Microsoft Outlook: Calling VBA Class Module function using VBScript - - Web Development, Programming, SEO

Tuesday, March 24, 2009

Microsoft Outlook: Calling VBA Class Module function using VBScript

Although it is not recommended by Microsoft (see below), a procedure can be created in VBA (Visual Basic for Applications) and called using VBScript (Visual Basic Scripting Edition). By default, VBA is not initialised disabled when Outlook is started for performance reasons. If Outlook is started and an item opened (containing VBScript which calls a VBA procedure in the ThisOutlookSession Class Module), an error will occur as the required VBA procedure/function will not be available. For procedures to be called from the ThisOutlookSession module, security settings need to be adjusted to allow the macros to run.
To call a VBA procedure in the ThisOutlookSession module from VBScript, create an Outlook.Application object, which will then allow the procedure to be called.

ThisOutlookSession Module (VBA):
Public Sub sendMessage(ByVal message As String)
MsgBox (message)

End Sub
Outlook Form Code (VBScript):
Function Item_Close()
Set myOlApp = CreateObject("Outlook.Application")
End Function
When the form/item is closed, the VBScript Item_Close() event is triggered which then calls the sendMessage() procedure in the ThisOutlookSession module, passing the required message as a string.

Quoted From Microsoft
"You cannot directly call a procedure stored in a module other than ThisOutlookSession."
"You can also use the standard Visual Basic syntax to create and call a function, and you can also pass arguments by value or by reference. You cannot directly call a procedure stored in a module other than ThisOutlookSession.

This functionality is available only as a side effect of the architecture of Outlook and the object model. It was not intended to be available as part of Outlook development environment. Because of known issues regarding this functionality, Microsoft recommends that you do not create a solution based on this functionality."

1 comment:

  1. At work with outlook and other mail files I advise ti use next software-view read inbox outlook,it is reliable tool and has free status as far as I can see,also utility help you with your mailbox recovery of Microsoft Outlook, when it is corrupted or lost,can restore mail server after a failure, they will do it, otherwise, all mailboxes may be lost,keeps a replica of user's mailbox on your HDD, users usually misknow this fact, but it is very important and gives a chance to recover your data,can help you to retrieve your data from a file with *.ost extension, that is stored on your hard drive,can process files with *.ost and *.pst extensions and recover data, that was considered to be lost.


This website is using cookies. More details