Emailing from excel with some problems...

conradcliff

Board Regular
Joined
Feb 24, 2010
Messages
58
Hey guys, so..I'm trying to figure out how I can send a simple email from excel with he body consisting of certain cell values.

I got some code from rondebruin.nl but when I took the suggestions on how to tweak the message body it breaks the code. here's what I have:

Code:
Sub Mail_small_Text_Outlook()
'Working in Office 2000-2010
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With ThisWorkbook.Sheets("PrintableInvoice")
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  .Range("ThisInvoiceEmailInfo")
    End With

    On Error Resume Next
    With OutMail
        .To = "cliff@mydomain.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
I get:

run-time error '429':
ActiveX component can't create object

it then highlights the "With ThisWorkbook.Sheets("PrintableInvoice")" line of code and when I mouse over that it tells me that < object variable or With block variable not set>

I've looked these things up but can seem to figure it out :confused:...any help would be much appreciated :)
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Wow, thanks so much for the quick reply, you're awesome! I named the cell O13 on the specified sheet with that name...is this method incorrect in that that's not actually a range?
 
Upvote 0
I don't think awesome applies to asking a question but does it work if you replace the range ThisInvoiceEmailInfo with the cell reference O13?
 
Upvote 0
Thanks for the reply, just did it but I get the same message..I've been able to send emails with different bits of code but not what I'm looking for really...and this code will work if I use the basic suggestion from here, it's only when I add to it from here that it breaks.
 
Upvote 0
Here are some screen shots of the issue:

ActiveX%20error%20%27429%27.PNG


Debug.PNG


variable%20not%20set.png

HBAuuwaTPvk0S2CizHjURQ
 
Upvote 0
Try calling it sheet1 or sheet2, in the vb editor it will have a reference to which sheet number it is. You're also going to have a problem once that gets working unless you've created a named range with that name.


I would personally create a string variable and put everything you want as a message body into that string variable because you don't have to do it using a with statement.

strbody = "Hi there " & PersonsName & "!" & vbCrLf & vbCrLf
strbody = strbody & ThisWorkbook.Sheets("PrintableInvoice").Range("O13").Text

Edit--
Sorry, I did add a variable not already included and changed those to line feeds, you can just leave the first line like it already was on yours and that would be fine, but I like emails to include personalized information :)
If you do have a cell with the persons first name or first and last name, adding a reference to the name in the email would be a nice touch, but not necessary.
 
Last edited:
Upvote 0
Thank you so much for the reply, I fear that I'm just a bit too ignorant to quite understand what you're saying though.

I think you want me to change "PrintableInvoice" to "Sheet1" or "Sheet2". I think the sheet number is currently like 9811..I'm not sure why but there seems to be triplets of all my sheets. Here's an image for reference:

excel%20problem.png


The sheet numbers are high because we built this workbook off an older one in which I was creating a new sheet for every new invoice so there were lots of sheets.

I think the creation o the string variable is just what you posted as:

strbody = "Hi there " & PersonsName & "!" & vbCrLf & vbCrLf
strbody = strbody & ThisWorkbook.Sheets("PrintableInvoice").Range("O13").Text

I tried using just the bottom line and also the bottom and top line and I tried changing the sheet name to "Sheet9811", "Sheet981", and "Sheet98" but I keep getting the same ActiveX error.

So sorry for my severe lack of knowledge, but thank you so much for your help.
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,569
Members
449,173
Latest member
Kon123

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