HOWTO: Performing OLE Automation with Visual Basic Script

Last reviewed: September 30, 1997
Article ID: Q165673
The information in this article applies to:
  • Microsoft Visual Basic, Scripting Edition, version 1.0

SUMMARY

Visual Basic Scripting Edition (VBScript), version 1.0, does not support the CreateObject function that is available in Visual Basic for Applications (VBA). The HTML object tag can be used in conjunction with Visual Basic Scripting to automate any OLE Automation server.

Note: VBScript 2.0 (and higher) now supports the CreateObject function. However, this version does not ship with the current version of Internet Explorer 3.0. Refer to http://www.microsoft.com/vbscript for more information on obtaining the latest version of VBScript 2.0.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following example demonstrates how the HTML object tag and Visual Basic Scripting can be used to send a message with the OLE Messaging Automation Object.

NOTE: Replace objOneRecip.Name = "Some Name" with a valid recipient name:

   <HTML>
   <HEAD>
   <TITLE>Sample Script to Send a MessagePage</TITLE>
   </HEAD>
   <BODY>
      <OBJECT ID="MAPI" WIDTH=10 HEIGHT=10
       CLASSID="CLSID:3FA7DEB3-6438-101B-ACC1-00AA00423326">
     </OBJECT>

   <SCRIPT LANGUAGE="VBScript">
   Dim oSession, objMessage, objOneRecip
   MAPI.Logon
   Set objMessage = MAPI.Outbox.Messages.Add
   Set objOneRecip = objMessage.Recipients.Add
       objOneRecip.Name = "Some Name"
       objOneRecip.Type = 1
       objOneRecip.Resolve 1
   objMessage.subject = "Test MAPI/OLE VB Message w/ole object - explicit"
   objMessage.Text = "Like you really wanted this.. Please Delete this
   test"
   objMessage.Send 0,0,0

   </SCRIPT>
   </BODY>
   </HTML>
Keywords          : OleMsg ActMsg kbinterop
Technology        : kbole
Version           : 1.0
Platform          : WINDOWS
Issue type        : kbhowto
Solution Type     : kbcode


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.