Run time error 2147467259 (80004005) outlook does not recognise one or more names - VBA

Latha

Board Regular
Joined
Feb 24, 2011
Messages
146
hi team,

I have the below code to send emails and gives an error (Run time error 2147467259 (80004005) outlook does not recognise one or more names) when I try to run.

Please help me to resolve this issue.


Code:
Sub SendAMail_Click()

    Application.ScreenUpdating = False
 
    
    Dim BottomA As Long
    BottomA = Sheets("TOBESENT").Range("A" & Rows.Count).End(xlUp).Row
    Dim x As Long
    x = 0
    Dim Director As Range
    Dim findDir As Range
    Dim ws As Worksheet
    
    Dim olapp As Outlook.Application
    Dim olmail As Outlook.MailItem
    Dim rng1 As Range
    Dim rng2 As Range
    Dim StrBody1 As String
    Dim StrBody2 As String
    Dim StrBody3 As String
    Dim LResult As String
    Dim i As Long
    Dim SigString As String
    Dim Signature As String
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
  
    
        Sheets("TOBESENT").Range("A1:A" & BottomA).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
        ("A1:A" & BottomA), Unique:=True
    Set rnguniques = Sheets("TOBESENT").Range("A2:A" & BottomA).SpecialCells(xlCellTypeVisible)
    If Sheets("TOBESENT").FilterMode Then Sheets("TOBESENT").ShowAllData
    For Each Director In rnguniques
        Set ws = Nothing
        On Error Resume Next
        Set ws = Worksheets(Director.Value)
        On Error GoTo 0
        If ws Is Nothing Then
            Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "New"
            Set rng1 = Sheets("TOBESENT").Range("A1:J1").SpecialCells(xlCellTypeVisible)
                rng1.Copy
                Sheets("New").Range("A1").PasteSpecial Paste:=xlPasteValues
                
                For Each findDir In Sheets("TOBESENT").Range("A1:A" & BottomA)
                If findDir = Director Then
                    x = x + 1
                    
                    findDir.EntireRow.Copy ActiveSheet.Cells(x + 1, "A")
                    
                    
                End If
            Next findDir
            
            Worksheets("New").Columns("B:B").Select
            Worksheets("New").Columns("B:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("New").Range("K1"), Unique:=True
'            Worksheets("New").Range("K1").Select
'            Selection.Clear
            Worksheets("New").Range("L1").Formula = "=CONCATENATE(R[1]C[-1],""; "",R[2]C[-1],""; "",R[3]C[-1],""; "",R[4]C[-1],""; "",R[5]C[-1],""; "",R[6]C[-1],""; "",R[7]C[-1],""; "",R[8]C[-1],""; "",R[9]C[-1],""; "",R[10]C[-1],""; "",R[11]C[-1],""; "",R[12]C[-1],""; "",R[13]C[-1],""; "",R[14]C[-1])"
            Worksheets("New").Range("M1").Formula = "=CONCATENATE(R[1]C[-10],""; "",R[2]C[-10],""; "",R[3]C[-10],""; "",R[4]C[-10],""; "",R[5]C[-10],""; "",R[6]C[-10],""; "",R[7]C[-10],""; "",R[8]C[-10],""; "",R[9]C[-10],""; "",R[10]C[-10],""; "",R[11]C[-10],""; "",R[12]C[-10],""; "",R[13]C[-10],""; "",R[14]C[-10],""; "",R[15]C[-10],""; "",R[16]C[-10],""; "",R[17]C[-10],""; "",R[18]C[-10],""; "",R[19]C[-10],""; "",R[20]C[-10],""; "",R[21]C[-10],""; "",R[22]C[-10],""; "",R[23]C[-10],""; "",R[24]C[-10],""; "",R[25]C[-10],""; "",R[26]C[-10],""; "",R[27]C[-10],""; "",R[28]C[-10],""; "",R[29]C[-10],""; "",R[30]C[-10],""; "",R[31]C[-10],""; "",R[32]C[-10],""; "",R[33]C[-10],,""; "",R[34]C[-10])"
            Worksheets("New").Range("L1:M1").Copy
            Worksheets("New").Range("L1:M1").PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False

        End If
        x = 0

            Worksheets("New").Range("B1").Select
            Set olapp = New Outlook.Application
            Set olmail = olapp.CreateItem(olMailItem)
                           
'            SigString = Environ("appdata") & _
'                    "\Microsoft\Signatures\Latha.htm"
'
'            If Dir(SigString) <> "" Then
'                Signature = GetBoiler(SigString)
'            Else
'                Signature = ""
'            End If
        On Error GoTo 0
            With olmail
                .SentOnBehalfOfName = "servicedesk@altisource.com"
                .To = Sheets("New").Range("M1").Value
                .CC = Sheets("New").Range("A2").Value & Sheets("New").Range("L1").Value
                'Specific email Ids can be added like this
                '"Vikram.Poovanna@altisource.com;" & "Sunil.Kumar2@altisource.com;" & "Gaurav.Kansal@altisource.com"
                .Subject = "IMPORTANT: Password Reset - Registration"
                'with subject the cell value can be added like this "Ageing and Open Tickets Follow Up <" & Cells(i, 3).Value & ">"
                
                'Set body format to HTML
                 
                                 
                
                StrBody1 = "<P STYLE='font-family:Calibri ;font-size:15'>Addressed" & "<p>"

                StrBody2 = "<P STYLE='font-family:Calibri ;font-size:15'>We have found your name in the list of non-registered users in self-service password reset (SSPR) portal. Registering to this portal is mandatory." & "<br><br>" & "In future, we require each and every employee to reset their network password on their own without calling Service Desk." & "<br><br>" & _
                "<P STYLE='font-family:Calibri ;font-size:15'>We need you to get yourself and your team members (if any) registered into Password Reset portal as soon as possible." & "<p>"
    
                StrBody3 = "<P STYLE='font-family:Calibri ;font-size:15'> For registering, refer to the attached guide. You can also refer to " & "<a href=""http://nav8apspnp01/sites/IT/tts/SitePages/Home.aspx"">Self-Service Password Reset - End User Support Documentation" & "</a>" & " for details."
                ' font style or size can be added like this "<P STYLE='font-family:Trebuchet MS (10) ;font-size:13'> Refer to "
                
                StrBody4 = "<P STYLE='font-family:Calibri ;font-size:15'> for details."
                StrBody5 = "<P STYLE='font-family:Calibri ;font-size:15'>Technology Service Desk" & "<br>" & "<br>" & "<P STYLE='font-family:Trebuchet MS (10) ;font-size:13'>For faster service, you may use the Self Service tool to submit your ticket at  " & "<a href=""https://servicedesk.ascorp.com/CAisd/pdmweb.exe"">http://servicedesk.ascorp.com" & "</a>"
                .HTMLBody = StrBody1 & StrBody2 & StrBody3 & "<br>" & "<br>" & "<br>" & "<br>" & StrBody5

                
                '.Attachments.Add TempFilePath & TempFileName & FileExtStr
                '.Attachments.Add ("\\bpk8fsasnp01\Commonshare3\ITOperation\Password Reset - Do It Yourself!.msg")
                '.Attachments.Add ("\\bpk8fsasnp01\Commonshare3\ITOperation\SSPR -EndUser - SupportDoc - ASPS.pdf")
                .Attachments.Add ("C:\Users\dlatha\Desktop\Password Reset Guide.PDF")
                .Send
                
            End With
             On Error GoTo 0
        Application.DisplayAlerts = False
        Sheets("New").Delete
        Application.DisplayAlerts = True
        ThisWorkbook.Save
'End With
Next
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
so, where in the code does it fail ?

does the person you are saying is sending on behalf of, exist within outlook?
 
Upvote 0
It fails at the line ".Send"

yes the mailbox I have mentioned in the "on behalf of" does exists and I have permission to send emails from that mailbox.
 
Upvote 0
if you put Option Explicit about the sub at the top of that sheet and then compile


Code:
[COLOR=#ff0000][B]Option Explicit[/B][/COLOR]
Sub SendAMail_Click()

    Application.ScreenUpdating = False


    Dim BottomA As Long
    BottomA = Sheets("TOBESENT").Range("A" & Rows.Count).End(xlUp).Row
    Dim x   As Long
    x = 0
    Dim Director As Range
    Dim findDir As Range
    Dim ws  As Worksheet

    Dim olapp As Outlook.Application
    Dim olmail As Outlook.MailItem
    Dim rng1 As Range
    Dim rng2 As Range
    Dim StrBody1 As String
    Dim StrBody2 As String
    Dim StrBody3 As String
    Dim LResult As String
    Dim i   As Long
    Dim SigString As String
    Dim Signature As String
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh  As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window


    Sheets("TOBESENT").Range("A1:A" & BottomA).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
                                                                                                      ("A1:A" & BottomA), Unique:=True
    Set rnguniques = Sheets("TOBESENT").Range("A2:A" & BottomA).SpecialCells(xlCellTypeVisible)
    If Sheets("TOBESENT").FilterMode Then Sheets("TOBESENT").ShowAllData
    For Each Director In rnguniques
        Set ws = Nothing
        On Error Resume Next
        Set ws = Worksheets(Director.Value)
        On Error GoTo 0
        If ws Is Nothing Then
            Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "New"
            Set rng1 = Sheets("TOBESENT").Range("A1:J1").SpecialCells(xlCellTypeVisible)
            rng1.Copy
            Sheets("New").Range("A1").PasteSpecial Paste:=xlPasteValues

            For Each findDir In Sheets("TOBESENT").Range("A1:A" & BottomA)
                If findDir = Director Then
                    x = x + 1

                    findDir.EntireRow.Copy ActiveSheet.Cells(x + 1, "A")


                End If
            Next findDir

            Worksheets("New").Columns("B:B").Select
            Worksheets("New").Columns("B:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("New").Range("K1"), Unique:=True
    '            Worksheets("New").Range("K1").Select
    '            Selection.Clear
            Worksheets("New").Range("L1").Formula = "=CONCATENATE(R[1]C[-1],""; "",R[2]C[-1],""; "",R[3]C[-1],""; "",R[4]C[-1],""; "",R[5]C[-1],""; "",R[6]C[-1],""; "",R[7]C[-1],""; "",R[8]C[-1],""; "",R[9]C[-1],""; "",R[10]C[-1],""; "",R[11]C[-1],""; "",R[12]C[-1],""; "",R[13]C[-1],""; "",R[14]C[-1])"
         [COLOR=#0000ff]   Worksheets("New").Range("M1").Formula = "=CONCATENATE(R[1]C[-10],""; "",R[2]C[-10],""; "",R[3]C[-10],""; "",R[4]C[-10],""; "",R[5]C[-10],""; "",R[6]C[-10],""; "",R[7]C[-10],""; "",R[8]C[-10],""; "",R[9]C[-10],""; "",R[10]C[-10],""; "",R[11]C[-10],""; "",R[12]C[-10],""; "",R[13]C[-10],""; "",R[14]C[-10],""; "",R[15]C[-10],""; "",R[16]C[-10],""; "",R[17]C[-10],""; "",R[18]C[-10],""; "",R[19]C[-10],""; "",R[20]C[-10],""; "",R[21]C[-10],""; "",R[22]C[-10],""; "",R[23]C[-10],""; "",R[24]C[-10],""; "",R[25]C[-10],""; "",R[26]C[-10],""; "",R[27]C[-10],""; "",R[28]C[-10],""; "",R[29]C[-10],""; "",R[30]C[-10],""; "",R[31]C[-10],""; "",R[32]C[-10],""; "",R[33]C[-10],,""; "",R[34]C[-10])"[/COLOR]
            Worksheets("New").Range("L1:M1").Copy
            Worksheets("New").Range("L1:M1").PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False

        End If
        x = 0

        Worksheets("New").Range("B1").Select
        Set olapp = New Outlook.Application
        Set olmail = olapp.CreateItem(olMailItem)

    '            SigString = Environ("appdata") & _
                 '                    "\Microsoft\Signatures\Latha.htm"
    '
    '            If Dir(SigString) <> "" Then
    '                Signature = GetBoiler(SigString)
    '            Else
    '                Signature = ""
    '            End If
        On Error GoTo 0
        With olmail
            .SentOnBehalfOfName = "servicedesk@altisource.com"
            .to = Sheets("New").Range("M1").Value
            .CC = Sheets("New").Range("A2").Value & Sheets("New").Range("L1").Value
    'Specific email Ids can be added like this
    '"Vikram.Poovanna@altisource.com;" & "Sunil.Kumar2@altisource.com;" & "Gaurav.Kansal@altisource.com"
            .Subject = "IMPORTANT: Password Reset - Registration"
    'with subject the cell value can be added like this "Ageing and Open Tickets Follow Up <" & Cells(i, 3).Value & ">"

    'Set body format to HTML



            StrBody1 = "Addressed " & ""

            StrBody2 = "We have found your name in the list of non-registered users in self-service password reset (SSPR) portal. Registering to this portal is mandatory." & "" & "In future, we require each and every employee to reset their network password on their own without calling Service Desk." & "" & _
                       "We need you to get yourself and your team members (if any) registered into Password Reset portal as soon as possible." & ""


            StrBody3 = " For registering, refer to the attached guide. You can also refer to " & "Self-Service Password Reset - End User Support Documentation" & "" & " for details.               ' font style or size can be added like this "

    'Refer to "

            StrBody4 = " for details."
            StrBody5 = "Technology Service Desk" & "" & "" & "For faster service, you may use the Self Service tool to submit your ticket at  " & "http://servicedesk.ascorp.com" & ""
            .HTMLBody = StrBody1 & StrBody2 & StrBody3 & "" & "" & "" & "" & StrBody5


    '.Attachments.Add TempFilePath & TempFileName & FileExtStr
    '.Attachments.Add ("\\bpk8fsasnp01\Commonshare3\ITOperation\Password Reset - Do It Yourself!.msg")
    '.Attachments.Add ("\\bpk8fsasnp01\Commonshare3\ITOperation\SSPR -EndUser - SupportDoc - ASPS.pdf")
            
            .Attachments.Add ("C:\Users\dlatha\Desktop\Password Reset Guide.PDF")
        [COLOR=#ff0000]    .Send[/COLOR]

        End With
        On Error GoTo 0
        Application.DisplayAlerts = False
        Sheets("New").Delete
        Application.DisplayAlerts = True
        ThisWorkbook.Save
    'End With
    Next
End Sub

the section in blue does that actually return proper email accounts
 
Upvote 0
if I add Option explicit.. its showing error "Variable not defined' at the line

Set rnguniques = Sheets("TOBESENT").Range("A2:A" & BottomA).SpecialCells(xlCellTypeVisible)

Yes. the blue line are giving the correct email addresses.
 
Upvote 0
yup. I wrote it like this
Dim rnguniques as range

Though the same error and error points to .Send
 
Upvote 0
olMail is one of the pre-defined variables in Outlook Object library. Use a different variable name.
 
Upvote 0

Forum statistics

Threads
1,216,749
Messages
6,132,496
Members
449,730
Latest member
SeanHT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top