OL97: VBScript Cannot Access Characters in the Body Property

Last reviewed: February 27, 1998
Article ID: Q162995
The information in this article applies to:
  • Microsoft Outlook 97

SYMPTOMS

When you use Visual Basic Scripting Edition (VBScript), you cannot programmatically insert information into the body of an Outlook item without completely replacing the body.

CAUSE

The Outlook object model provides only one property for this part of the item, the Body property. The Body property enables you to programmatically create and delete the body text, but it does not enable you to insert or modify information that is in the middle of the body.

For example, you may have a mail item with the following text in the body:

   -------------------------------
   Thank you for using:


   We appreciate your business.
   -------------------------------

If you want to programmatically insert a product name in between the lines, there is no method or property available that will not completely replace all of the body, as shown in the following examples.

   Item.Body = "This is new text"    This example would completely replace
                                     the existing text with the new text.

   Item.Body = ""                    This example would completely delete
                                     the text.

Because different server applications (Outlook, WordMail, and so on.) can provide the Body property of a mail message, there is no one, common object model to facilitate modifications within the Body property.

WORKAROUND

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 engineers 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/refguide/default.asp

The following Outlook VBScript enables you to insert text within the Body property of the example in the "Cause" section. It does so by parsing the existing text and re-inserting new body text.

   Sub Item_Open()
   ' Dimension X to hold the return of the InStr function.
   Dim X
   ' Get the location of the second carriage return.
   X = Instr(Instr(1,Item.Body,Chr(13),1)+1,Item.Body,Chr(13),1)
   ' Get the text from the beginning of the body to the second carriage
   ' return.
   TempA = Left(Item.Body, X)
   ' Get the rest of the text.
   TempB = Mid(Item.Body, X + 1, Len(Item.Body))
   ' Create new text.
   NewText = "Gadget Company" + Chr(13)
   ' Insert new Body which includes new text.
   Item.Body = TempA + NewText + TempB
   End Sub

REFERENCES

   Article-ID: Q166368
   Title     : OL97: How to Get Help Programming with Outlook

   Article-ID: Q170783
   Title     : OL97: Q&A: Questions about Customizing or
               Programming Outlook


Additional query words: OutSol OutSol97

Keywords : kbprb kbprg
Version : 97
Platform : WINDOWS


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: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.