Results 1 to 5 of 5

Extract email address and copy into .To field

Threaded View

  1. #4
    Registered User
    Join Date
    08-16-2008
    Location
    Edmonton, Alberta, Canada
    Posts
    69

    Re: Extract email address and copy into .To field

    I made some headway. The code in red are the changes that I made.

    Sub Mail_Selection_WithSignature()
    
    Dim Rng As Range
    Dim NewMsg As Outlook.MailItem
    Dim objInsp As Outlook.Inspector
    Dim cbc As Office.CommandBarPopup
    Dim cbControls As Office.CommandBarControls
    Dim cbButton As Office.CommandBarButton
    Dim Sendto As String
    
    Set Rng = Nothing
        On Error Resume Next
        Set Rng = Selection.SpecialCells(xlCellTypeVisible)
        Sendto = Cells(ActiveCell.Row, "J").Value
        On Error GoTo 0
        
        If Rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
    
    Set NewMsg = CreateItem(olMailItem)
    
    NewMsg.Display
    
    Set objInsp = ActiveInspector
    If Not objInsp Is Nothing Then
      Set cbc = objInsp.CommandBars.FindControl(, 31145)
    End If
    
    If Not cbc Is Nothing Then
     Set cbControls = cbc.Controls
    End If
    
    For Each cbButton In cbControls
       If cbButton.Caption = "HP" Then
           cbButton.Execute
           Exit For
        End If
    Next
    
    With NewMsg
      .To = Sendto
      .CC = "test1@tst.com;test2@tst.com;test3@tst.com"
      .Subject = "Request for project updates."
      .HTMLBody = "<p>Hello,</p>" & _
      "<p>Please provide updates for the following projects.</p>" & _
       RangetoHTML(Rng) & _
        .HTMLBody
    End With
    
    ExitProc:
    Set cbControls = Nothing
    Set cbc = Nothing
    Set objInsp = Nothing
    Set NewMsg = Nothing
    End Sub
    This adds the name of the selected row to the .To field of the email.

    I still need to figure out how to deal with multiple rows. I would like to test column J if it's a duplicate name. If it's duplicate than only add the first name and create 1 email. If the 2nd name is different than create another email and include the selected row that's associated with that name, etc.

    Additionally, I would like the header row, A8 to L8 to always be added to the email. This way I only need to select the rows of projects that I need updates for. Alternately, I don't mind selecting this row I would just want to test the cell content in column J for the word "LPM". If it finds it then the code should skip to the next cell in column J.

    I've attached the revised worksheet.

    Any ideas anyone?

    Chris
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1