Results 1 to 5 of 5

Extract email address and copy into .To field

Threaded View

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

    Extract email address and copy into .To field

    Hello,

    I currently have a workbook that I track various projects with and periodically I will need to get updates for them. I modified the following code that I found in this forum, which works pretty well.

    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
    
    Set Rng = Nothing
        On Error Resume Next
        Set Rng = Selection.SpecialCells(xlCellTypeVisible)
        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 = ""
      .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
    What I haven't been able to figure out is how to extract the email address from the selected rows, which is in column J, and add it to the .To field in the email. Additionally, if I select multiple rows I would like to test if it's a duplicate address so that only 1 gets copied to the email.

    In the attached workbook you'll note that there are just names in column J. This is all I need as the exchange server will resolve the address.

    Please let me know if you require any additional information. Thanks.

    Regards,
    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