This is very useful if you want to create an auto reporting application.
I use this a lot to create auto report template for my daily tasks and help me to save a lots of time.
The code for generating outlook emails is as below
=====================================================
Sub outlook_mail()
Dim App As Object
Dim item As Object
Dim strzipFile As String
Dim esubject As String
Dim sendto As String
Dim ccto As String
Dim text As String
strzipFile = "Specify file name you want to attached here"
' setting up outlook application
Set App = CreateObject("Outlook.Application")
Set itm = App.CreateItem(olMailItem)
'mail address setting
fromme = "my mail@adress"
sendto = "mail@adress"
ccto = "mail@adress"
'title setting
esubject = "This my test mail"
'body content
text = text & "This is my test mail" & vbNewLine
text = text & "Regards" & vbNewLine
text = text & "Nidzam" & vbNewLine
With itm
.Subject = esubject
.SentOnBehalfOfName = fromme
.To = sendto
.cc = ccto
'for this example I disable the attchment function
'.Attachments.Add (strzipFile)
.Body = text
'this will display the email before you send it
.Display
'if you don't want to display the mail, put below command instead of .Display
'.Send
'to clear memory
Set App = Nothing
Set itm = Nothing
ende:
End With
End Sub
=====================================================Sorry guys. i don't have example for this one because
I just wrote in one of work related template. I'm too lazy today
to paste it into another workbook. I'll just print screen the outlook
mail so you can have an idea how the output looks like.
I'll try to elaborate more on report automation using outlook if got the time.
No comments:
Post a Comment