macro for e-mailing excel file using outlook

  • Thread starter Thread starter matt
  • Start date Start date
M

matt

I have created a macro to produce a report and I would
like to finish the macro off by getting it to e-mail the
report to the recipients. I have tried the macro below and
although it works and sends the file it doesn't enable me
to include a message in the body of the e-mail.

ActiveWorkbook.SendMail Recipients:=Range("c4"),
subject:=Range("c2")

I have tried one or two bits of code that I have found on
internet sites but they never seem to work properly.

The report will be saved before the e-mail bit of the
macro is run and I am using excel 2000 and outlook
98....can anyone help?

Cheers
Miserable Matt
 
I have used this and it works great just do not upgrade
to outlook XP or the outlook object model guard security
patch or you will get a pop up every time

'E-mail out using outlook not used at this time due to
out object model guard
' be sure to reference microsft outlook
' Dim objotech As Outlook.Application
' Dim objmailitemtech As Outlook.MailItem
' Set objotech = New Outlook.Application
' Set objmailitemtech = objotech.CreateItem(olMailtItem)
' With objmailitemtech
' .To = acontactlistinoutlook
' .CC = sameasabove
' .Body = txtMessage
' .SentOnBehalfOfName = yourname
' .send
' End With
' Set objmailitemtech = Nothing
' Set objotech = Nothing


Or if you have a smtp server you can use this code
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' Set the CDOSYS configuration fields to use port 25
on the SMTP server.

With Flds
.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing
") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP
server.
.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserve
r") = "smtp.yourserver.com"
.Item
("http://schemas.microsoft.com/cdo/configuration/smtpconne
ctiontimeout") = 10
.Update
End With

' Build HTML for message body.



' Apply the settings to the message.
With imsg
Set .Configuration = iConf
.To = addressto 'Enter a valid email address."
.From = addressfrom 'ToDo: Enter a valid email
address.
.Subject = " "
.HTMLBody = txtMessage
.send
End With
End Sub
 
Back
Top