emailing excel vba

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

Emailing from Excel VBA

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

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

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Hide separate columns in Excel 2010

If you want to hide columns not adjacent to each other for example, Columns A, C and E then:-

1) Click on the fist column to be hidden i.e. A

2) Press and hold down the CTRL key

3) While holding the CTRL key, left click on the rest of the columns you want to hide i.e. C and E

4) Right click and choose Hide

View all Excel hints and tips


Server loaded in 0.08 secs.