ThrottleWorks
Excel Ninja
Hi,
I am using below mentioned code to create e-mails.
Sometimes, while running the code, Outlook get closed thus results in error.
Can anyone please tell me how do I open Outlook with VBA (if it is close).
I tried few Google options but it is not working for me.
I am using below mentioned code to create e-mails.
Sometimes, while running the code, Outlook get closed thus results in error.
Code:
Option Explicit
Sub FlodAutomation()
Dim SubjectLine As Variant
Dim FromEmail As Variant
Dim ToEmail As Variant
Dim CcEmail As Variant
Dim OutApp As Variant
Dim OutMail As Variant
Dim vInspector As Variant
Dim wEditor As Variant
Dim TempLr As Long
Dim FlodSht As Worksheet
Set FlodSht = ThisWorkbook.Worksheets("Email Sheet")
FromEmail = ""
ToEmail = FlodSht.Range("C2").Value
CcEmail = FlodSht.Range("C3").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = FromEmail
.To = ToEmail
.CC = CcEmail
.Subject = ThisWorkbook.Worksheets("Mapping").Range("A4").Value
.Body = ""
'.Attachments.Add (ThisWorkbook.Worksheets("Macro").Range("P4").Value)
TempLr = FlodSht.Cells(EmailTemplate.Rows.Count, 8).End(xlUp).Row
FlodSht.Range("H1:P" & TempLr).Copy
Set vInspector = OutMail.GetInspector
Set wEditor = vInspector.WordEditor
wEditor.Application.Selection.Start = Len(.Body)
wEditor.Application.Selection.End = wEditor.Application.Selection.Start
.Display
wEditor.Application.Selection.Paste
End With
Application.CutCopyMode = 1
End Sub
Can anyone please tell me how do I open Outlook with VBA (if it is close).
I tried few Google options but it is not working for me.