Sending mail with macro is creating Excel ghost processes

Davy80

New Member
Joined
Jun 5, 2018
Messages
9
Dear all,

Who can help me with the code below.
I'm not an expert on vba and the code is creating 2 ghost processes of excel which will not be released once the mail is send.

Mailing works fine, but somehow excel won't release the processes.

Can someone help me to get the correct code?
It problably has something to do wtih the .to and .subject because their value are read from the excel file .

I can't kill excel enterely because people using this workbook may have other excel files opened..

Here's the code:

Code:
Sub Mail_PE()

Dim Response As Integer

' Displays a message box with the yes and no options.
Response = MsgBox(prompt:="Mail DCM to the Product Engineer?", Buttons:=vbYesNo)

' If the Yes is selected
If Response = vbYes Then

'Step 1:  Declare variables

Dim OLApp As Object
Dim OLMail As Object

'Step 2:  Open Outlook start a new mail item


Set OLApp = CreateObject("Outlook.Application")
Set OLMail = OLApp.CreateItem(0)
OLApp.Session.Logon

'Step 3:  Build your mail item and send

 With OLMail

    .to = Worksheets("Macro Data").Range("F14").Text
    .CC = ""
    .BCC = ""
    .Subject = Worksheets("Macro Data").Range("D8").Text
    .HTMLBody = _
    "[I]...stuff here with link to file in body....."[/I]
  

   ' Try to send
    On Error Resume Next
    .Send
    Application.Visible = True
    If Err Then
      MsgBox "E-mail is not send. Please send manual.", vbExclamation
    Else
      MsgBox "E-mail send succesfully. We will start on the DCM asap.", vbInformation
    End If
    On Error GoTo 0

  End With
 
'Step 4:  Memory cleanup

    Set OLMail = Nothing
    Set OLApp = Nothing
  Else
         ' If the No-button is selected.
         Exit Sub

      End If
 End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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