Article ID: 162995 - Last Review: February 12, 2007 - Revision: 1.3

OL97: VBScript Cannot Access Characters in the Body Property

This article was previously published under Q162995
Expand all | Collapse all

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 a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104)

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice)

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (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
				

REFERENCES

166368  (http://support.microsoft.com/kb/166368/EN-US/ ) OL97: How to Get Help Programming with Outlook

170783  (http://support.microsoft.com/kb/170783/EN-US/ ) OL97: Q&A: Questions about Customizing or Programming Outlook

APPLIES TO
  • Microsoft Outlook 97 Standard Edition
Keywords: 
kbprogramming KB162995
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations