Outlook Error when sending email from excel

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I keep getting error 462: The remote server does not exist or is unavailable. Any ideas?

Here is my code:

Code:
Public Sub SendButton_EMAIL_Click()
    
    'Email Declarations
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem


     'Set References
    On Error GoTo OutlookErrors
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    Set OutlookEventClass.oMailItem = OutMail
                 
     With OutMail
                    .SentOnBehalfOfName = FromLabel_EMAIL.Caption
                    .To = ToTextBox_Email.Text
                    .CC = CCTextbox_EMAIL.Text
                    .BCC = BCCTextbox_EMAIL.Text
                    .Subject = SubjectTextbox_EMAIL.Text
                    .Body = BodyTextbox_EMAIL.Text
                    If Not AttachmenLabel_EMAIL.Tag = "" Then
                        .Attachments.Add (AttachmenLabel_EMAIL.Tag)
                    End If
                    .Send
      End With
    
    OutApp.Quit
    Set OutMail = Nothing
    Set OutApp = Nothing

OutlookErrors:
            Debug.Print Err.Number & " : " & Err.Description
             
            If Not OutMail Is Nothing Then
                OutMail.Close (olDiscard)
            End If
            Set OutMail = Nothing
            
            If Not OutApp Is Nothing Then
                Set OutApp = Nothing
            End If

            Exit Sub
    
End Sub
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This might be a stupid question, but is Outlook installed?
 
Upvote 0
Lol yea its installed.

Turns out my attachment string had a error in it. I am still curious how I could perfect this code to make it better in regards to not having to open a new outlook if one is open and to handle any errors and close objects after the task is done. I want to close outlook ONLY if i created that object, if the instance was already open then I will use it but not close it.
 
Last edited:
Upvote 0
Which version of Outlook is installed?
 
Upvote 0
Do you know how to check if mailitem is still open? I was going to use this code to send instead so I do not get any security messages but given sendkeys is so finicky i wanted to check if it its still open and if so close it.

Code:
                    .Display
                    Set myInspector = .GetInspector
                    myInspector.Width = 0.1
                    myInspector.Height = 0.1
                    '.Send
                    'Give outlook some time to display the message
                    Application.Wait (Now + TimeValue("0:00:02"))


                    'Activate the window that the mail item is in and use sendkeys to send the message
                    myInspector.Activate
                    SendKeys "%s", True

                   'Check if sendkeys worked by seeing if mailitem is still open and close it
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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