Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email Address-Duplicates? (XL97:SR2)

    I use the following code to create an Outlook98 Email message with or without attaching various files from within XL. The issue I am having is when the address of an individual (Var2) as defined in the global address book runs across an address where the first and last name are similar. The code errors out as it can not distinguish between the similar addresses such as: C Maxwell or C Maxwellhouse

    Is it possible to have an exact match of Var2 and the global address list?

    Sub NewEmailCode()
    Dim objOLook As New Outlook.Application
    Dim objOMail As MailItem
    Dim i As Long
    TrueFalse = Range("AttachFile")

    Set objOLook = New Outlook.Application
    Set objOMail = objOLook.CreateItem(olMailItem)

    With objOMail
    .To = "" & Var2 & ""
    .Subject = "" & Var4 & ""
    .Body = .Body & vbCrLf & " "
    .Body = "" & Var11 & ","
    .Body = .Body & vbCrLf & " "
    .Body = .Body & vbCrLf & "" & Var5 & ""
    .Body = .Body & vbCrLf & " "
    .Body = .Body & vbCrLf & "" & Var6 & " "
    .Body = .Body & vbCrLf & " "
    .Body = .Body & vbCrLf & "" & Var7 & ""
    .Body = .Body & vbCrLf & " "
    .Body = .Body & vbCrLf & "" & Var8 & ""
    .Body = .Body & vbCrLf & " "

    .Body = .Body & vbCrLf & "" & Var9 & ""
    .Body = .Body & vbCrLf & "" & Var10 & ""
    .Body = .Body & vbCrLf & " "
    .Body = .Body & vbCrLf & " "

    If TrueFalse = "True" Then
    For i = 1 To 5
    File2Attach = ActiveCell.Offset(0, i + 2)

    If File2Attach > " " Then
    .Attachments.Add "" & Var3 & "" & File2Attach & ""
    End If
    Next
    End If
    ' .Display
    .Send
    End With
    Set objOMail = Nothing
    Set objOLook = Nothing
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Email Address-Duplicates? (XL97:SR2)

    I don't know the answer to your question, but this may help a bit: the Recipient object in Outlook has a Resolve method. It returns True if Outlook can resolve the name.

    Instead of .To = Var2, use:

    Dim objORecipient As Outlook.Recipient
    Set objORecipient = objOMail.Recipients.Add(Var2)
    If Not objORecipient.Resolve Then
    ' there is a problem
    MsgBox "Can't resolve " & Var2
    ' exit now?
    End If

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Email Address-Duplicates? (XL97:SR2)

    Hans,

    The resolve method did not work. I'm still encountering the problem.

    John

Posting Permissions

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