VB script to delete part of email

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
            objAtt.Delete                      
        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.
ChWCITAsked:
Who is Participating?
 
jimbobmcgeeCommented:
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

    'PUT THIS WITH THE OTHER DIMS
    Dim lngPos as Long

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

HTH

J.
0
 
ChWCITAuthor Commented:
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.
0
 
ChWCITAuthor Commented:
Never min jimbobmcgee, I figured it out.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.