Object Variable or With block variable not set

Doedtman

Board Regular
Joined
May 21, 2010
Messages
92
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
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,521
Messages
6,179,278
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top