OL2002: Calling a VBA Procedure from VBScript (292177)



The information in this article applies to:

  • Microsoft Outlook 2002

This article was previously published under Q292177

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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: 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 answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:

287530 OL2002: Questions About Custom Forms and Outlook Solutions


Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbinfo KB292177