here I am trying to send out a mail to multiple recipients from outlook vba.
the recipient mail address is taken from column A of excel sheet. Whne I run the below code the error "Run Time error 1004; Method 'cells of object'_Global' failed"
how to send the same mail to multiple recipients at the same time.
To:[email protected]; [email protected]; [email protected] CC:[email protected]; [email protected] Subject: test mail
Code:
Sub Sendmail()
Dim olItem As Outlook.MailItem
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim sPath As String
Dim iRow As Long
iRow = 1
sPath = "XX"
' // Excel
Set xlApp = CreateObject("Excel.Application")
' // Workbook
Set xlBook = xlApp.Workbooks.Open(sPath)
' // Sheet
Set xlSht = xlBook.Sheets("Sheet1")
Do Until IsEmpty(Cells(iRow, 1))
Recip = Cells(iRow, 1).Value
' subject = Cells(iRow, 2).Value
' Atmt = Cells(iRow, 3).Value '
' // Create e-mail Item
Set olItem = Application.CreateItem(olMailItem)
With olItem
Set olRecip = .Recipients.Add(Recip)
.CC = xlSht.Range("B1")
.subject = "test"
.Display
.Send
End With
' // Close
xlBook.Close SaveChanges:=True
' // Quit
xlApp.Quit
'// CleanUp
iRow = iRow + 1
Loop
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSht = Nothing
Set olItem = Nothing
End Sub