Microsoft KB Archive/162995

= OL97: VBScript Cannot Access Characters in the Body Property =

Article ID: 162995

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Outlook 97 Standard Edition

-



This article was previously published under Q162995



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 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://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

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

