VB script to delete part of email

Posted on 2004-10-21
Medium Priority
Last Modified: 2010-05-02
I am using the following script to forward all incoming emails that meet a certain rule to my pager.  

Sub StripAndForward(thisMail As Outlook.MailItem)
        Const strAddress    As String = "email@domain.com"
        Const blnAutoSend   As Boolean = True
        Dim objFwd As Outlook.MailItem
        Dim objAtt As Outlook.Attachment
        For Each objAtt In thisMail.Attachments
        Next objAtt
        Set objFwd = thisMail.Forward          
        objFwd.Recipients.Add strAddress        
        If blnAutoSend = True Then objFwd.Send Else objFwd.Display
        Set objFwd = Nothing
        Set objAtt = Nothing
        Set thisMail = Nothing                  
    End Sub

The problem is, there is a character limit on the pager.  I would like to delete all text in the email above a certain keyword (ie. "Problem:") before this email is forwarded.  Is there anything I can add to this script to accomplish this.  Thanks in advance.
Question by:ChWCIT
  • 2
LVL 16

Accepted Solution

jimbobmcgee earned 2000 total points
ID: 12370839
Try this:

    'PUT THESE JUST AFTER Sub StripAndForward()
    Const lngPagerMax as Long = 255       'MAX LENGTH OF PAGER MESSAGE
    Const strTextToFind as String = "Problem:"       'TEXT TO USE AS START POINT OF MESSAGE

    Dim lngPos as Long

    'PUT THIS AFTER objFwd.Recipients...
    lngPos = InStr(1, thisMail.Body, strTextToFind)
    objFwd.Body = Mid(thisMail.Body, lngPos, lngPagerMax)



Author Comment

ID: 12371915
Thanks again jimbobmcgee.  This worked great.  Do you also know how to delete the subject line when sending the email.  I am trying to make the email as small as possible.

Author Comment

ID: 12373033
Never min jimbobmcgee, I figured it out.  

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question