Solved

VB script to delete part of email

Posted on 2004-10-21
336 Views
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
            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.
0
Question by:ChWCIT
    3 Comments
     
    LVL 16

    Accepted Solution

    by:
    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
     

    Author Comment

    by:ChWCIT
    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
     

    Author Comment

    by:ChWCIT
    Never min jimbobmcgee, I figured it out.  
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    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…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    856 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now