Exiting excel with VBA, and sending a mail without prompting

Dinictus

Board Regular
Joined
Mar 19, 2002
Messages
162
Hi,

I have a beatiful piece of code here:

*******
Sub Email()

Dim myOutlook As Object
Dim myMailItem As Object

Set otlApp = CreateObject("Outlook.Application")
Set otlNewMail = otlApp.CreateItem(olMailItem)
fName = ActiveWorkbook.Path & "" & ActiveWorkbook.Name

With otlNewMail

.To = "Mister.Dinictus@Dinictuscorp.com"
.Subject = "You are soo goooood " & Date
.Body = Worksheets("GOOOOOD").Range("A1")
'.Attachments.Add fName
.Display

End With

Set otlNewMail = Nothing
Set otlApp = Nothing
Set otlAttach = Nothing
Set otlMess = Nothing
Set otlNSpace = Nothing
'otlApp.Quit


syntaxt that will actually really really send this composed mail

End Sub
**************


Now, this composes a mail and all, but does not actually SEND the mail. I want this code to also send it! Is this possible from VBA? I will probably be promted by outlook but I will look into that later.

Another thing is, I want excel to quit with a VBA commando.
Now ofcourse "ActiveWorkbook.Close" closes the workbook but what code closes excel entirely? Is this possible?? I hope so.


Please help me out and will post a reaaallly good joke as a reward. :lol

Cheers.
Din.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Can't you just add .Send?

And Application.Quit?
 
Upvote 0
:o

The application.quit thing works great in combination the Application.DisplayAlerts = False.

Thanks!

The .send will probably also work but what do I put before it?
I tried:
.myMailItem.send
.otlNewMail.send

but I get object does not support blabla.

but the.....

AAAAAAHHH.


.send WORKS! :twisted:
outlook doesn't even ask me yes or no. This is great!
Thanks man.
 
Upvote 0

Forum statistics

Threads
1,224,867
Messages
6,181,480
Members
453,046
Latest member
Excelvbaexpert

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