Unable to Send E-mails, run-time error 1004 - excel

While running this code i get run-time error 1004, "Application-defined object defined error". This error is showing up on the line starting with "NumRows = Worksheets("Data")" in the first function. Can someone just check on this code and let me know what's wrong here, i am new to VBA macros with limited knowledge.
Public Sub loopCheck()
Dim NumRows As Integer
Dim eID As String
Dim eName As String
Dim eEmail As String
Dim supportGroup As String
Dim managerEmail As String
Dim acName As String
Dim x As Integer
Application.ScreenUpdating = False
NumRows = Worksheets("Data").Range("A5", Range("A5").End(xlDown)).Rows.Count ' Set numrows = number of rows of data.
Worksheets("Data").Range("A5").Select ' Select first record.
For x = 1 To NumRows ' Establish "For" loop to loop "numrows" number of times.
eID = Worksheets("Data").Range("A" & x + 4).Value
eName = Worksheets("Data").Range("B" & x + 4).Value
eEmail = Worksheets("Data").Range("C" & x + 4).Value
supportGroup = Worksheets("Data").Range("F" & x + 4).Value
managerEmail = Worksheets("Data").Range("G" & x + 4).Value
acName = Worksheets("Data").Range("I" & x + 4).Value
'Prepare table to be sent locally.
Worksheets("Data").Range("AA5").Value = eID
Worksheets("Data").Range("AB5").Value = eName
Worksheets("Data").Range("AC5").Value = eEmail
Worksheets("Data").Range("AF5").Value = supportGroup
managerEmail = managerEmail + ";" + Worksheets("Data").Range("AA1").Value
'Call Emails function.
Call Emails(acName, eEmail, managerEmail)
ActiveCell.Offset(1, 0).Select
Next
Application.ScreenUpdating = True
End Sub
Public Sub Emails(x As String, y As String, z As String)
Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Dim a As String
Dim b As String
Dim c As String
a = y
b = z
c = x
Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(0)
With newEmail
.To = a
.CC = b
.BCC = ""
.Subject = Worksheets("MF").Range("A1") & c
.Body = ""
.display
Set xInspect = newEmail.getInspector
Set pageEditor = xInspect.WordEditor
Worksheets("MF").Range("A9").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
Worksheets("MF").Range("A3").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
Worksheets("Data").Range("AA4:AF5").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
Worksheets("MF").Range("A5").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
Worksheets("MF").Range("A7").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
.send
Set pageEditor = Nothing
Set xInspect = Nothing
End With
Set newEmail = Nothing
Set outlook = Nothing
End Sub

I have made some corrections in your code and it works at my end . Please try this. Mainly it relates to setting workbook and worksheets references properly otherwise your code seems to be okay:
Public Sub loopCheck()
Dim NumRows As Integer
Dim eID As String
Dim eName As String
Dim eEmail As String
Dim supportGroup As String
Dim managerEmail As String
Dim acName As String
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim x As Integer
Set ws1 = ThisWorkbook.Worksheets("Data") ' Set workbook & worksheet reference
Set ws2 = ThisWorkbook.Worksheets("MF") '' Set workbook & worksheet reference
NumRows = ws1.Range("A5", Range("A5").End(xlDown)).Rows.Count ' Set numrows = number of rows of data.
ws1.Range("A5").Select ' Select first record.
For x = 1 To NumRows ' Establish "For" loop to loop "numrows" number of times.
eID = ws1.Range("A" & x + 4).Value
eName = ws1.Range("B" & x + 4).Value
eEmail = ws1.Range("C" & x + 4).Value
supportGroup = ws1.Range("F" & x + 4).Value
managerEmail = ws1.Range("G" & x + 4).Value
acName = ws1.Range("I" & x + 4).Value
'Prepare table to be sent locally.
With ws1
.Range("AA5").Value = eID
.Range("AB5").Value = eName
.Range("AC5").Value = eEmail
.Range("AF5").Value = supportGroup
managerEmail = managerEmail + ";" + ws1.Range("AA1").Value
'Call Emails function.
Call Emails(acName, eEmail, managerEmail)
ActiveCell.Offset(1, 0).Select
End With
Next
Application.ScreenUpdating = True
End Sub
Public Sub Emails(x As String, y As String, z As String)
Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Dim a As String
Dim b As String
Dim c As String
Dim str As String
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
a = y
b = z
c = x
Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(0)
Set ws2 = ThisWorkbook.Worksheets("MF")
str = ws2.Range("A1").Value & c
With newEmail
.To = a
.CC = b
.BCC = ""
.Subject = str
.Body = ""
.Display
Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor
Set ws1 = ThisWorkbook.Worksheets("Data")
ws2.Range("A9").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
ws2.Range("A3").Copy
pageEditor.Application.Selection.Paste xlValuesAndFormat (wdFormatPlainText)
ws1.Range("AA4:AF5").Copy
pageEditor.Application.Selection.Paste xlValuesAndFormat (wdFormatPlainText)
ws2.Range("A5").Copy
pageEditor.Application.Selection.Paste xlValuesAndFormat (wdFormatPlainText)
ws2.Range("A7").Copy
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
.Send
Set pageEditor = Nothing
Set xInspect = Nothing
End With
Set newEmail = Nothing
Set outlook = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

Either your worksheet must be active or you have to address your range like this:
NumRows = Worksheets("Data").Range("A5", Worksheets("Data").Range("A5").End(xlDown)).Rows.Count

Related

Set date of Outlook task from cell value via Excel

I am trying to create a task in Outlook with reminder via Excel.
My code gives
Run-time error '438': Object doesn't support this property or method
on line
.StartDate = CDate(DelDate)
How do I set date of task from cell value?
Sub RectangleRoundedCorners1_Click()
Dim OutApp As Object
Dim OutTask As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutTask = OutApp.CreateItem(olTaskItem)
Dim ws As Worksheet
Dim Ads As String
Dim Subj As String
Dim Body As String
Dim DelDate As Date
Set ws = ActiveSheet
Ads = ws.Cells(4, 2).Value
Subj = ws.Cells(7, 2).Value
Body = ws.Cells(4, 9).Value
DelDate = ws.Cells(10, 6).Value
DelHour = ws.Cells(12, 6).Value
Dim myRecipient As Object
Set myRecipient = OutTask.Recipients.Add(Cells(4, 2))
myRecipient.Resolve
If myRecipient.Resolved Then
With OutTask
.Subject = Subj
.StartDate = CDate(DelDate)
.DueDate = CDate(DelDate)
.ReminderTime = CDate(DelDate)
.Body = Body
.Assign
.Display
End With
End If
Set OutTask = Nothing
Set OutApp = Nothing
End Sub

Email Body Loop Values

I am attempting to loop through a column (n=96) in my worksheet, when it comes across a value <10 I would like the macro to open outlook and email offset values (four columns across) from the values it found.
I've generated a working example though it seems to be limited to only one example I've tested. I think I am approaching it from the wrong angle.
Sub SendReminderMail()
Dim p As Long
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim iCounter As Integer
Dim MailDest As String
'If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
p = 2
Do Until Trim$(Cells(p, 1).Value) = ""
If Cells(p, 1).Value <= 10 Then
Set OutLookMailItem = OutLookApp.CreateItem(0)
With OutLookMailItem
.To = "Emailaddress etc"
.Subject = "Reminder: " & Cells(1, 7).Value
.Body = Cells(p, 1).Offset(0, 4).Value
.Display
End With
End If
p = p + 1
Loop
End Sub
How do I set it up to loop through all the <10 values and tell it to paste the offset values into the body of the email?
I think that you need to split this into two blocks of code.
First block would iterate through rows, check criteria and, if needed, call the second one, so the mail sending Sub, passing by necessary parameters.
Someting similar to the below code:
Sub SendReminderMail(ByVal MailSubject As String, mailBody As String)
Dim p As Long
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim iCounter As Integer
Dim MailDest As String
'If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set OutLookMailItem = OutLookApp.CreateItem(0)
With OutLookMailItem
.To = "Emailaddress etc"
.Subject = MailSubject
.Body = mailBody
.Display
End With
End Sub
Sub IterateThroughRows()
Dim p As Integer
Dim Sht As Worksheet
Dim MailSubject As String
Dim mailBody As String
Set Sht = ThisWorkbook.Sheets("SheetName")
p = 2
Do Until Sht.Cells(p, 1).Value = ""
If Cells(p, 1).Value <= 10 Then
mailBody = mailBody + " | " + Sht.Cells(p, 1).Offset(0, 4).Value
End If
p = p + 1
Loop
Call SendReminderMail(MailSubject, mailBody)
MailSubject = "Reminder: " & Sht.Cells(1, 7).Value
End Sub

How do I separate into a new cell in excel after every "-" in subject from outlook emails

I am trying to get the string after a word that gives me the needed data and all the phrase after every "-" into a new cell in excel except in RE: , where I omit "RE:" and only leave the TS... ticket ID.
This code works by selecting the emails in outlook and then running the macro for only that selected emails.
This is an example of a subject that has the
Example Subject
RE: TS001889493 - Translation failure - Inbound - ( VEXP/ HONCE/ Document Type 214 - Map AVE_NMHG_I_214_4010_XML_SAT - Error Conditional Relationship Error in N103 (0066) [ ref:_00D50c9MW._5000z1J3cG8:ref ]
Example of body
Dear Valued Trading Partner,
We received the attached 214 transactions from Sender ID: VEXP/ Receiver ID: HONCE that failed due to Conditional Relationship Error in the N1_03 (0066).
As per the map logic, If either N103 or N104 is present, then the other is required as they are in conditional relationship with each other.
But in the input file received, N104 value is missing hence the error.
Transaction Details: #4#
Attached
Please correct and resend the data.
Thank you,
Simon Huggs | Sass support - Basic
ref:_00D50c9MW._5000z1J3cG8:ref
What happens in the #num# is that it gets the sum of all these after making a match of the "TS" ticket ID.
This is the code I have up until now
Option Explicit
Sub WritingTicketNumberAndfailuresnew()
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Object
Dim rCount, STicket, SticketNumber As Long
Dim bXStarted As Boolean
Dim enviro As String
Dim strPath, SSubject As String
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim olItem As Outlook.MailItem
Dim obj As Object
Dim strColS, strColB, sassupport, sMailDateReceived, SFrom As String
Dim Actions1, Actions2, Actions3, Actions4 As Boolean
Dim I, cnt, email_needed As Integer
' Get Excel set up
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
On Error GoTo 0
'Open a specific workbook to input the data the path of the workbook under the windows user account
enviro = CStr(Environ("USERPROFILE"))
strPath = enviro & "\Documents\topthreeticket.xlsx"
Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")
' Add column names
xlSheet.Range("A1") = "Email Subject"
xlSheet.Range("B1") = "Map Name"
xlSheet.Range("C1") = "Case Number"
xlSheet.Range("D1") = "No. Of Failures"
xlSheet.Range("E1") = "Date"
xlSheet.Range("F1") = "Week Number"
sassupport = "sassuport#sass.com"
On Error Resume Next
'Find the next empty line of the worksheet
rCount = xlSheet.Range("A" & xlSheet.Rows.Count).End(-4162).Row
'needed for Exchange 2016. Remove if causing blank lines.
rCount = rCount + 1
' get the values from outlook
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each obj In Selection
Set olItem = obj
'collect the fields for ticket number and failure count
strColS = olItem.Subject
strColB = olItem.Body
SFrom = olItem.SenderEmailAddress
sMailDateReceived = olItem.ReceivedTime
Dim sFailures, stmp1, stmp2, stmp3 As String
Dim RegX As Object, Mats As Object
Dim Found As Boolean
' Check the number of failures from body
sFailures = "0"
stmp1 = strColB
Set RegX = CreateObject("VBScript.RegExp")
With RegX
.Global = True
.Pattern = "#\d+#"
Set Mats = .Execute(stmp1)
End With
If (RegX.Test(stmp1)) Then
stmp2 = Mats(0)
Found = True
stmp3 = Mid(stmp2, 2, Len(stmp2) - 2)
sFailures = stmp3
Else
With RegX
.Pattern = "#d\d+"
Set Mats = .Execute(stmp1)
End With
If (RegX.Test(stmp1)) Then
stmp2 = Mats(0)
Found = True
stmp3 = Mid(stmp2, 2, Len(stmp2) - 1)
sFailures = stmp3
End If
End If
Set Mats = Nothing
Set RegX = Nothing
Dim tmp As String
Dim RegX2 As Object, Mats1 As Object
tmp = strColS
Set RegX2 = CreateObject("VBScript.RegExp")
With RegX2
.Global = True
.Pattern = "TS00\d{7}"
Set Mats1 = .Execute(tmp)
End With
If (RegX2.Test(tmp)) Then
Set Mats1 = RegX2.Execute(tmp)
tmp = Mats1(0)
Else
With RegX2
.Pattern = "T.S\d{9}"
Set Mats1 = .Execute(tmp)
End With
If (RegX.Test(tmp)) Then
tmp = Mats1(0)
End If
End If
Set Mats1 = Nothing
Set RegX2 = Nothing
Dim tempticketnum, tmpdate As String
Dim ticketnumposition As Integer
'write them in the excel sheet
If SFrom = sassupport Then
xlSheet.Range("A" & rCount) = strColS
xlSheet.Range("B" & rCount) = tmp2
xlSheet.Range("C" & rCount) = tmp
xlSheet.Range("D" & rCount) = sFailures ' number of failures
xlSheet.Range("E" & rCount) = sMailDateReceived
rCount = rCount + 1
End If
Next
Set olItem = Nothing
Set obj = Nothing
Set currentExplorer = Nothing
Set xlSheet = Nothing
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
You can use the SPLIT function in VBA, something like so
Sub x()
Dim s As String
Dim a() As String
s = "this-will-test-this-out"
a = Split(s, "-")
Range("a1").Resize(UBound(a) + 1, 1).Value = Application.Transpose(a)
End Sub

bulk emails with excel

Trying to create a bulk email workbook out of Excel using VBA code which includes embedded images. I'm unable to apply a "For i" to the code and can't figure out how to email from an entire list with a ListObject table. For the script below, the Sheet referenced is "Message Generator." I'm trying to send an individual email to everyone in the list until the value in the row in Column B = 0. However, the Integer I set for the loop seems to return the value 0, as though there are no values in the rows and columns at all.
Anyone know how I can send create a workbook to send bulk emails? See below for the script. Thank you!
Dim MainWB As Workbook
Dim olApp As Outlook.Application
Dim olemail As Outlook.MailItem
Dim fso As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim SigPath As String, SigText As String
SigPath = Environ("AppData") & "\Microsoft\Signatures\New.htm"
Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile(SigPath)
SigText = ts.ReadAll
ts.Close
Set fso = Nothing
Set MainWB = ActiveWorkbook
Dim Subject As String
Dim Body As String
Dim i As Integer
Dim l As Integer
l = NumberOfNonBlankRowsInColumn(2) - 2 'subtract 2 header rows
Set olApp = New Outlook.Application
For i = 0 To l
Set olemail = olApp.CreateItem(olMailItem)
Subject = MainWB.Sheets("Message Generator").Range("B3").Offset(i, 0).Value
Body = MainWB.Sheets("Message Generator").Range("AB3").Offset(i, 0).Value
With olemail
.BodyFormat = olFormatHTML
.To = "UTOAI#outlook.com"
.Subject = Subject
.Body = Body
.Attachments.Add "C:\Users\Jacka\Documents\Test\logo.jpg"
.HTMLBody = "<img src='cid:logo.jpg'" & "width='309.5' height='39.5'><br>" & _vbanewline & .HTMLBody & SigText
.Display
End With
Set olemail = Nothing
Next i
Set olApp = Nothing
End Sub
Function NumberOfNonBlankRowsInColumn(souceCol As Integer) As Integer
Dim NumberOfRowsInColumn As Integer, j As Integer
Dim CurrentRowValue As String
NumberOfRowsInColumn = Cells(Rows.Count, sourceCol).End(xlUp).row
For j = 1 To NumberOfRowsInColumn
CurrentRowValue = Cells(j, sourceCol).Value
If IsEmpty(CurrentRowValue) Or CurrentRowValue = "" Then
Exit For
End If
Next j
NumberOfNonBlankRowsInColumn = (j - 1)
End Function
Try not to make this mistake. The reason it worked sometimes and not others is because I had a value in the row above my column which later deleted. Therefore, I set NonBlankRowsInColumn to 2 (where the values begin) and done. See the edited function below.
Function NumberOfNonBlankRowsInColumn(souceCol As Integer) As Integer
Dim NumberOfRowsInColumn As Integer, j As Integer
Dim CurrentRowValue As String
NumberOfRowsInColumn = Cells(Rows.Count, sourceCol).End(xlUp).row
For j = 2 To NumberOfRowsInColumn
CurrentRowValue = Cells(j, sourceCol).Value
If IsEmpty(CurrentRowValue) Or CurrentRowValue = "" Then
Exit For
End If
Next j
NumberOfNonBlankRowsInColumn = (j - 1)
End Function

How to create a to string?

I am trying to create an Outlook email for multiple recipients.
I have two sheets 1 and 2.
I want the code in sheet 1 column B to look into Sheet 2 column A and pick up all the email addresses matched the codes and create an email with list recipients in tostring and do repeat task for second code till its empty.
Also attach files corresponding to that code in column c in sheet 1.
Its in the Sheet 2 column B
I have clients' names in sheet 1 column B and there is corresponding names in sheet 2 Column A and email addresses in Column B.
I created below code. How do I create a to string in VBA?
Sub GenerateEmail()
i = 2 ' selects row 2 ,since row 1 ,i am keeping for titles
Dim wbBook As Excel.Workbook
Dim doText As DataObject
Dim wsSheet As Excel.Worksheet
Dim x As Variant
Dim myemail As String
Dim myrange As Range
Dim n As Range
Dim sm2 As Range
Set wbBook = ThisWorkbook
Set sm2 = ThisWorkbook.Sheets("Sheet 2").Range("A2:A1000")
Set sm1 = ThisWorkbook.Sheets("Sheet 1").Range("B2:B1000")
Do Until ThisWorkbook.Sheets("Sheet 1").Cells(i, "B").Value = ""
EmailTo = tostring
BCC = ThisWorkbook.Sheets("Sheet 1").Range("J3").Value
Subj = ThisWorkbook.Sheets("Sheet 1").Range("J4").Value
Path = "N:\Folder 1\Folder 2\Folder 3\Folder 3\Result\"
FileName = ThisWorkbook.Sheets("Sheet 1").Cells(i, 3)
SM = ThisWorkbook.Sheets("Sheet 1").Cells(i, 2)
x = Replace(Range("Content1").Value, "<PROJECTION DATE1>", Format(Range("GenerationMonth").Value, "mmmm"))
x = x & Replace(Range("Content2").Value, "<PROJECTION DATE2>", Format(Range("GenerationMonth").Value, "mmmm-yyyy"))
x = x & ThisWorkbook.Sheets("Sheet 3").Range("Content3").Value
Msg = x
Application.ScreenUpdating = False
Application.StatusBar = "Preparing email..."
Application.DisplayAlerts = False
'Variables for MS Outlook.
'Variables for MS Outlook.
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "Cleint1#Hotmail.com"
.To = EmailTo
.BCC = "Cleint1#Hotmail.com"
.Subject = "This is my subject" & Format(DateAdd("m", -1, Date), "mmmm yyyy")
.Attachments.Add Path & FileName
.Display
.BodyFormat = olFormatPlain
.Body = Msg
'send
End With
i = i + 1
Set doText = Nothing
Application.CutCopyMode = False
Loop
Cells(7, "J").Value = "Outlook msg count =" & i - 1
Set OutMail = Nothing
Set OutApp = Nothing
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Workbooks(MyFile).Close
End Sub
This is one way to start your loop and get the "To:" variable.
I comment out most of the code because I don't have your workbook and the code would not work in my situation.
Sub DoItEmail()
'Dim doText As DataObject
Dim x As Variant
Dim myemail As String
Dim myrange As Range
Dim n As Range
Dim sm2 As Range
Dim OutApp As Object
Dim OutMail As Object
'==================================================================
Dim sh As Worksheet, ws As Worksheet, wb As Workbook
Dim Rws As Long, Rng As Range, c As Range
Dim Rws2 As Long, Rng2 As Range, b As Range, SndTo As String
Set sh = Sheets("Sheet1")
Set ws = Sheets("Sheet2")
Application.ScreenUpdating = 0
With sh
Rws = .Cells(.Rows.Count, "A").End(xlUp).Row
Set Rng = .Range("A2:A" & Rws)
End With
With ws
Rws2 = .Cells(.Rows.Count, "C").End(xlUp).Row
Set Rng2 = .Range("C2:C" & Rws2)
End With
For Each c In Rng.Cells
For Each b In Rng2.Cells
If b = c Then
SndTo = b.Offset(0, 1) 'this would be your "to:" variable
'MsgBox SndTo & " is the To: variable"
'EmailTo = tostring
BCC = sh.Range("J3").Value
Subj = sh.Range("J4").Value
'Path = "N:\Folder 1\Folder 2\Folder 3\Folder 3\Result\"
'FileName = sh.Cells(i, 3)
'SM = sh.Cells(i, 2)
' x = Replace(Range("Content1").Value, "<PROJECTION DATE1>", Format(Range("GenerationMonth").Value, "mmmm"))
' x = x & Replace(Range("Content2").Value, "<PROJECTION DATE2>", Format(Range("GenerationMonth").Value, "mmmm-yyyy"))
' x = x & ThisWorkbook.Sheets("Sheet 3").Range("Content3").Value
' Msg = x
Application.ScreenUpdating = False
'Application.StatusBar = "Preparing email..."
Application.DisplayAlerts = False
'Variables for MS Outlook.
'Variables for MS Outlook.
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "Cleint1#Hotmail.com"
.To = SndTo
.BCC = "Cleint1#Hotmail.com"
.Subject = "This is my subject: " & Format(DateAdd("m", -1, Date), "mmmm yyyy")
'.Attachments.Add Path & FileName
.Display
.BodyFormat = olFormatPlain
.Body = Msg
'send
End With
i = i + 1
Set doText = Nothing
Application.CutCopyMode = False
Cells(7, "J").Value = "Outlook msg count =" & i
Set OutMail = Nothing
Set OutApp = Nothing
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Workbooks(MyFile).Close
End If
Next b
Next c
Application.StatusBar = False
End Sub

Resources