OL2000: Calling a VBA Procedure from VBScript

ID: Q221827


The information in this article applies to:
  • Microsoft Outlook 2000


SUMMARY

It is technically possible to call a Visual Basic for Appliciations procedure from Visual Basic Scripting Edition (VBScript), but because this functionality was not designed to be part of the overall development environment built into Outlook, Microsoft does not recommend building a solution using this approach.

NOTE: Because Outlook was not designed to support this functionality and because this functionality is not documented, Microsoft Product Support Services cannot provide support for issues related to using this functionality.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
If you create a Visual Basic for Applications procedure in the ThisOutlookSession module window, you can then call the procedure using the Application object. For example, if you create the following Visual Basic for Applications procedure

Sub MyProc(strParam)
   MsgBox strParam
End Sub 
you can then call it using the following syntax from VBScript:

Application.MyProc "This is from VBScript!" 
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.

The reasons to not use this functionality include, but are not necessarily limited to:
  • By default, Outlook Visual Basic for Applications is not initialized, for performance reasons, when you start Outlook. This means that if you start Outlook, open an item, and run the VBScript code, it will produce an error because Visual Basic for Applications is not available at that time.


  • This functionality has not gone through the standard testing procedures that planned features are subject to. Therefore, there is an increased risk of encountering other problems and it is not known what other problems may occur.


  • This functionality may not be available in future versions of Outlook.


As an alternative to calling Visual Basic for Applications code from VBScript, you can create a Visual Basic automation server, install it using a Visual Basic Setup program, and then launch the Visual Basic component by using the CreateObject method in VBScript.


REFERENCES

For additional information about available resources and answers to commonly asked questions about Microsoft Outlook 2000 solutions, please see the following article in the Microsoft Knowledge Base:

Q146636 OL2000: Questions About Custom Forms and Outlook Solutions

Additional query words: OL2K OutSol OutSol2000 vbscript

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.