+ Reply to Thread
Results 1 to 6 of 6

Method 'To' of object '_MailItem failed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-04-2014
    Location
    calgary, canada
    MS-Off Ver
    Excel 2013
    Posts
    108

    Method 'To' of object '_MailItem failed

    Run-time error '-2114715382 (81f4010a)':
    Method 'To' of object '_MailItem failed

    this is the error message i am getting on this code - BUT only on one laptop. this code is used by multiple people using different office versions and different operating systesm (7 and 8.1). i am highlighting the line where the code stops. any suggestions would be great. the specs of teh laptop that this error is occuring on are - windows 8.1 and office 2013

    Sub Button2593_Click()
        Dim Fname As String
        Dim EP As String
        Dim FDate As String
        Dim FQtr As String
        Dim OutApp As Object
        Dim Omsg As Object
        Dim FQuarter As Integer
        Dim myAddressee As String
        
        Dim Msg As String, Ans As Variant
        
           
         
        Msg = "HAVE YOU COMPLTED THE MOST RECENT HEALTH VISIT SECTION AT THE TOP OF REPORT? Have you set the re-visit dates for the Compliance Issues on the Business Review? And have you listed ALL LSM activities? Most Important: Are you connected to the G: and the VPN?"
         
        Ans = MsgBox(Msg, vbYesNo)
         
        Select Case Ans
             
        Case vbYes
        
       If Cells(247, 7) = "" Then
       
       Msg = "Naughty Naughty - you did NOT do enough service times - Better get Back at 'er, Minimum service times is 5!! Better slow it down there cowboy"
       
       Ans = MsgBox(Msg, vbOKOnly)
       
       Exit Sub
       
       
       Else
       
      
       
       
        
        Application.ScreenUpdating = False
        
        If Len(Sheets("fresh thinking audit").Range("c4")) > 0 Then
            Score = Range("c411").Text
            EP = Range("C4").Value
            FQtr = Range("m12").Value
            FDate = MonthName(Month(Date), True) & " " & DatePart("d", Date) & ", " & Year(Date)
            Fname = "EP" & Sheets("fresh thinking audit").Range("c4").Value
            FQuarter = WorksheetFunction.Ceiling(Month(Date) / 3, 1)
            If Dir("c:\rbr", vbDirectory) = "" Then
                MkDir ("c:\rbr")
            End If
            
            Sheets("fresh thinking audit").ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\rbr\" & Fname & " " & "MM" & " " & FDate & " " & Score & ".pdf", openafterpublish:=False
            
            Sheets("SOS Timing").ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\rbr\" & Fname & " SOS Timing " & FDate & ".pdf", openafterpublish:=False
            
            Sheets("Business Review").ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\rbr\" & Fname & " Business Review " & FDate & ".pdf", openafterpublish:=False
         
            
                    
    With Sheets("Unacceptable")
      .Visible = True
      .Copy
      ActiveWorkbook.SaveAs _
          Filename:="c:\rbr\" & EP & " Unacceptable " & FQtr & ".csv", _
          FileFormat:=xlCSV
      ActiveWorkbook.Close False
      .ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\rbr\" & Fname & " Unacceptable " & FDate & ".pdf", _
               openafterpublish:=False
      .Visible = True
    End With
      
    
    FileCopy "C:\rbr\" & EP & " Unacceptable " & FQtr & ".csv", "G:\RBR CSV Files\" & EP & " Unacceptable " & FQtr & ".csv"
    FileCopy "C:\rbr\" & Fname & " " & "MM" & " " & FDate & " " & Score & ".pdf", "G:\rbr\" & Fname & " " & "MM" & " " & FDate & " " & Score & ".pdf"
    FileCopy "C:\rbr\" & Fname & " SOS Timing " & FDate & ".pdf", "G:\rbr\" & Fname & " SOS Timing " & FDate & ".pdf"
    FileCopy "C:\rbr\" & Fname & " Business Review " & FDate & ".pdf", "G:\rbr\" & Fname & " Business Review " & FDate & ".pdf"
    FileCopy "C:\rbr\" & Fname & " Unacceptable " & FDate & ".pdf", "G:\rbr\" & Fname & " Unacceptable " & FDate & ".pdf"
    
            
            Shell ("outlook")
            Set OutApp = GetObject("", "outlook.application")
            Set Omsg = OutApp.createitem(0)
            myAddressee = "rons@mtygroup.com"
            If Left(Sheets("fresh thinking audit").Range("n4"), 3) = "USA" Then
                myAddressee = myAddressee
                If Left(Sheets("fresh thinking audit").Range("n4"), 5) = "USA N" Then
                    myAddressee = myAddressee & ";Mears-denise@aramark.com"
                End If
            End If
            If Left(Sheets("fresh thinking audit").Range("n4"), 5) = "Non-T" Then
                myAddressee = myAddressee
            End If
            With Omsg
                .To = Sheets("fresh thinking audit").Range("m4")
                .cc = myAddressee
                .Subject = "RBR on EP" & Sheets("fresh thinking audit").Range("c4") & " for " & FQtr
                .body = "Restaurant Quality Report by " & OutApp.GetNamespace("MAPI").CurrentUser
                .Attachments.Add "C:\rbr\" & Fname & " " & "MM" & " " & FDate & " " & Score & ".pdf"
                .Attachments.Add "C:\rbr\" & Fname & " Business Review " & FDate & ".pdf"
                .Attachments.Add "C:\rbr\" & Fname & " SOS Timing " & FDate & ".pdf"
                'MsgBox .Address
                If myAddressee = "rons@mtygroup.com" Then .Attachments.Add "C:\rbr\" & Fname & " Unacceptable " & FDate & ".pdf"
                .send
            End With
            Call AddToOutlook
            Macro1
            
            Kill ("C:\rbr\" & Fname & " " & "MM" & " " & FDate & " " & Score & ".pdf")
            Kill ("C:\rbr\" & Fname & " SOS Timing " & FDate & ".pdf")
            Kill ("C:\rbr\" & Fname & " Business Review " & FDate & ".pdf")
            Kill ("C:\rbr\" & Fname & " Unacceptable " & FDate & ".pdf")
            Kill ("C:\rbr\" & EP & " Unacceptable " & FQtr & ".csv")
            
        End If
        
        End If
        
       
        
        
        
        Case vbNo
    GoTo Quit:
        End Select
         
    Quit:
    End Sub

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Method 'To' of object '_MailItem failed

    One idea... in the VBEditor check the Tools > References in a computer where it is working correctly and make sure the laptop has the same refs.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    calgary, canada
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: Method 'To' of object '_MailItem failed

    will do that now thanks Jerry

  4. #4
    Forum Contributor
    Join Date
    03-04-2014
    Location
    calgary, canada
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: Method 'To' of object '_MailItem failed

    so the references were the same. what i did was add .text to the end of the .to line

    .To = Sheets("fresh thinking audit").Range("m4").text
    and now it is working

  5. #5
    Registered User
    Join Date
    11-22-2016
    Location
    Belo Horizonte, Brazil
    MS-Off Ver
    2016 Professional
    Posts
    5

    Re: Method 'To' of object '_MailItem failed

    The same error was happening to me when trying to send a mail based on information inside a UserForm.

    The function for the e-mail was receiving the textboxes as parameter, and not their value (e.g: TxtBox.Value instead of simply TxtBox).

    Remember to always pass the specific property and it should work fine!

  6. #6
    Registered User
    Join Date
    08-20-2020
    Location
    New York
    MS-Off Ver
    2013
    Posts
    1

    Re: Method 'To' of object '_MailItem failed

    Thank you for your help. I was getting the same error but with the Method 'Subject' of object. This helped me greatly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Method 'Run' of object '_Application' failed
    By brl8 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-21-2015, 04:27 AM
  2. [SOLVED] Method range of object failed
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-02-2013, 06:55 AM
  3. Object error - method failed
    By okriskao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2009, 02:02 AM
  4. Method Add of object Sheet failed
    By JonMitsu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2006, 03:29 AM
  5. Replies: 0
    Last Post: 09-12-2005, 09:02 AM

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