Results 1 to 5 of 5

E-Mail Using Excel VBA & Outlook Error

Threaded View

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    E-Mail Using Excel VBA & Outlook Error

    Hi,

    I have set up a code to send E-mail using Outlook & Excel VBA. The Code is as below -

    Sub SendEMail()
    
        Dim OLApp As Outlook.Application
        Dim OLEMail As Outlook.MailItem
        Dim Adressbook As Worksheet, MailTo As String, Code As String, Counter As Integer, LR As Integer, Path As String
        
        
        Set OLApp = New Outlook.Application
        Set OLEMail = OLApp.CreateItem(olMailItem)
        Set Adressbook = ThisWorkbook.Worksheets("Adress Book")
    
        LR = Adressbook.Cells(Rows.Count, "A").End(xlUp).Row
        
        For Counter = 2 To LR
        
        MailTo = Adressbook.Cells(Counter, "C").Value
        Code = Adressbook.Cells(Counter, "A").Value
        Path = "C:\Users\J\Desktop\Send Dispatch Details\Attachments\" & Code & ".xlsm"
        
            If MailTo <> "" Or MailTo = Null Then
                'On Error GoTo Jumper
                With OLEMail
                    .Display
                    .BodyFormat = olFormatPlain
                    .To = MailTo
                    .Subject = "ZFI/" & Code & " - Dispatch Details"
                    .Attachments.Add Path
                    .Send                
                End With
            End If
            
    'Jumper:
        Next Counter
        
        Set OLApp = Nothing
        Set OLEMail = Nothing
        Set Adressbook = Nothing
        
    MsgBox "Dispatch Details E-Mailed!", vbOKOnly, "E-Mail"
        
    End Sub
    The Code Runs OK the 1st time, however during the second time it gives me the following error -

    Run-time error '462': The remote server machine does not exist or is unavailable
    Can anyone guide me how I can get rid of this?

    Helpful Links -

    http://support.microsoft.com/kb/189618

    http://support.microsoft.com/kb/178510
    Last edited by NeedForExcel; 07-19-2014 at 05:20 AM.
    Cheers!
    Deep Dave

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Intermittent error with email generation macro - pasting from excel to outlook mail
    By oenleunc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2014, 05:46 AM
  2. Send e-mail with image on body (.html) on e-mail manager <> outlook
    By mariotnc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2012, 09:28 PM
  3. code to attach the draft mail in new compose mail as attachment in outlook 2010
    By priya1987 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2012, 08:38 AM
  4. Print excel to PDF and e-mail the PDF with Outlook
    By Isadora in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2010, 11:16 AM
  5. e-mail from excel when outlook is not in use
    By Jignesh Khandwala in forum Excel General
    Replies: 5
    Last Post: 04-07-2006, 05:00 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