Avatar of Natasha Adams
Natasha Adams

asked on 

VBA code to automate emails in outlook using a Template

I am getting an error at .Send can you please let me know what is wrong?  Thanks in advance

Sub SendEmail()


Dim rng As Range
Dim row As Range
Dim cell As Range
Dim from As String
Dim template As String

'Specifies number of rows to search for email addresses
Set rng = Range("A1:A5")

Dim myOlApp As Object
Dim MyItem As Object

For Each row In rng.Rows
    For Each cell In row.Cells
   
        Set myOlApp = CreateObject("Outlook.Application")
        Set MyItem = myOlApp.CreateItemFromTemplate("C:\Users\.oft")
       
        With MyItem
                    .To = cell.Value
                    .Subject = "Help"
                    .Send
                End With
           
            Set MyItem = Nothing
            Set myOlApp = Nothing
       
    Next cell
    Next row

End Sub
Microsoft ExcelVBAVB Script

Avatar of undefined
Last Comment
Wayne Taylor (webtubbs)

8/22/2022 - Mon