emailing excel vba
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Emailing from Excel VBA

Emailing from Excel VBA

resolvedResolved · Medium Priority · Version 2003

replyReply Thu 9 Dec 2010, 15:55Delegate Raxit said...

Emailing from Excel VBA

How do I create an email that is populated but not sent, allowing the user to write in a message

For upcoming training course dates see: Pricing & availability

replyReply Wed 15 Dec 2010, 13:08Trainer Anthony said...

RE: Emailing from Excel VBA

Hi Raxit, thanks for your query. The subroutine below should do the trick. Note I've commented out some expressions at the end so the email remains on the screen, and you might want to uncomment various other expressions to hard code recipient names etc. Try it out and see how far you get.

__________________

Sub EmailWithOutlook()
'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String

'Turn off screen updating
Application.ScreenUpdating = False

'Make a copy of the active sheet and save it to
'a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "Temp.xls"
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\" & FileName

'Create and show the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
'.To = "someone@somedomain.com"
'Uncomment the line below to hard code a subject
'.Subject = "Look at my workbook!"
.Attachments.Add WB.FullName
.Display
End With

'Delete the temporary file
'WB.ChangeFileAccess Mode:=xlReadOnly
'Kill WB.FullName
'WB.Close SaveChanges:=False

'Restore screen updating and release Outlook
Application.ScreenUpdating = True
'Set oMail = Nothing
'Set oApp = Nothing
End Sub

_________________

Hope this helps,

Anthony

 

Please browse our web site to find out more about
excel classes and other Microsoft training courses.

Excel tip:

Creating custom lists

In Excel if you type in January in a cell, you can then copy this cell to replicate Febraury, MArch, April etc.

This list has come from Tools- options and Custom lists.

Therefore to save time and create your own list you can click on New (in Tools and custom list tab) and type out the lsit that you want copied quickly.

All you have to do is then type in the 1st word and you will be able to copy the rest of the list quickly.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard