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:
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