Consulting

Results 1 to 2 of 2

Thread: Find email address in email body to copy the adress to the destination addres

  1. #1

    Post Find email address in email body to copy the adress to the destination addres

    Hello,

    I want to make an autoforwarding macro, lets say i have so little VBA Experience that i use it as a modular set. We have multiple accounts (e.g, Secondary Adress,) working in an office, but all the comunications should be made using a unique Primary Adress. Browsing over the internet i manage to gather this code. But i cant retrieve the adress email from the mesagges body:

    ............................................Email body example...............................

    "Please Send to: adress 1; adress 2

    IMPORTANT TEXT
    IMPORTANT TEXT
    IMPORTANT TEXT
    IMPORTANT TEXT
    IMPORTANT TEXT
    IMPORTANT TEXT
    IMPORTANT TEXT

    Email signature
    -----------------------------------------------------------------------

    I just need to resend the IMPORTANT TEXT, using the adresses on the first line.

    Could somebody help me?

    See the code below:

    Sub SendNew(Item As Outlook.MailItem)

    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Dim strName As String
    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)

    strMsgBody = objMsg.Body
    MsgBox strMsgBody
    strEmailContents = ParseTextLinePair(strMsgBody, "Favor enviar a: ")

    MsgBox strEmailContents


    Msg = Item.Subject & " " & "a:"
    Style = vbYesNo + vbCritical + vbDefaultButton2
    Title = Item.Sender & " " & "desea enviar"
    Help = "DEMO.HLP"
    Ctxt = 1000

    Response = MsgBox(Msg, Style, Title, Help, Ctxt)

    If Response = vbNo Then
    MsgBox "No Autorizado!"
    Else

    objMsg.Body = Item.Body
    objMsg.Subject = "FW: " & Item.Subject
    objMsg.Recipients.Add "adress x"
    objMsg.Send
    MsgBox "Enviado!"
    End If

    End Sub

    Function ParseTextLinePair(strSource, strLabel)
    ' Sue Moshers code
    'commented out type declaration for VBS usgage take out fer VB usage
    Dim intLocLabel 'As Integer
    Dim intLocCRLF 'As Integer
    Dim intLenLabel 'As Integer
    Dim strText 'As String

    ' locate the label in the source text
    intLocLabel = InStr(strSource, strLabel)
    intLenLabel = Len(strLabel)
    If intLocLabel > 0 Then
    intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
    If intLocCRLF > 0 Then
    intLocLabel = intLocLabel + intLenLabel
    strText = Mid(strSource, _
    intLocLabel, _
    intLocCRLF - intLocLabel)
    Else
    intLocLabel = Mid(strSource, intLocLabel + intLenLabel)
    End If
    End If
    ParseTextLinePair = Trim(strText) ' this i like
    End Function

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    objMsg.Recipients.Add strEmailContents
    'or
    'objMsg.To = strEmailContents
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •