Hello!
I'm having some problems with a macro that I'm trying to set up. I'm trying to send out emails to a list of addresses in an excel spreadsheet, but I keep getting this error: "Object variable or With block variable not set" I'm not sure what this means, or how I can go about fixing this. Any help would be greatly appreciated!
Sub SendEmailWithAttachment()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim strEmail As String, strName As String
Dim lRowCount As Long
Set objOutlook = CreateObject("outlook.application") ' Start Outlook
lRowCount = 2 'get email address from column B
Do Until ActiveSheet.Cells(lRowCount, 2) = "" ' check for email
strEmail = ActiveSheet.Cells(lRowCount, 2).Value ' get email Address
strName = ActiveSheet.Cells(lRowCount, 1).Value ' get name of file
Set objOutlookMsg = objOutlook.CreateItem(olMailItem) ' create new email msg
With objOutlookMsg ' Fill email
.Subject = ActiveSheet.Cells(lRowCount, 6).Value 'Get subject from column F
.Body = ActiveSheet.Cells(lRowCount, 7).Value ' Get body from column G
.To = strEmail
.Attachments.Add ("C:\Documents and Settings\" & strName & ".pdf")
.Send
End With
lRowCount = lRowCount + 1
Loop
objOutlook.Quit
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
End Sub
Thanks,
Jodi
I'm having some problems with a macro that I'm trying to set up. I'm trying to send out emails to a list of addresses in an excel spreadsheet, but I keep getting this error: "Object variable or With block variable not set" I'm not sure what this means, or how I can go about fixing this. Any help would be greatly appreciated!
Sub SendEmailWithAttachment()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim strEmail As String, strName As String
Dim lRowCount As Long
Set objOutlook = CreateObject("outlook.application") ' Start Outlook
lRowCount = 2 'get email address from column B
Do Until ActiveSheet.Cells(lRowCount, 2) = "" ' check for email
strEmail = ActiveSheet.Cells(lRowCount, 2).Value ' get email Address
strName = ActiveSheet.Cells(lRowCount, 1).Value ' get name of file
Set objOutlookMsg = objOutlook.CreateItem(olMailItem) ' create new email msg
With objOutlookMsg ' Fill email
.Subject = ActiveSheet.Cells(lRowCount, 6).Value 'Get subject from column F
.Body = ActiveSheet.Cells(lRowCount, 7).Value ' Get body from column G
.To = strEmail
.Attachments.Add ("C:\Documents and Settings\" & strName & ".pdf")
.Send
End With
lRowCount = lRowCount + 1
Loop
objOutlook.Quit
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
End Sub
Thanks,
Jodi