Zehra has attended:
Access Intermediate course
Access Advanced course
VBA Emails
Hi
I need to generate an email from a command button on my worksheet.
I need the button to automatically generate an email to a predetermine person and group of persons.
I need the document to be automatically attached but only the active worksheet not the whole workbook.
Thanks
RE: VBA Emails
Zehra,
This is a bit complicated...
1) Use a Form or a Control-Panel style of worksheet, with recipient names, worksheet-to-send name, and command button.
2) To send a single worksheet, I think you'll need to either
-- create a new workbook, copy the selected worksheet to it, and save, or
-- activate the selected sheet and print it to PDF, if the receipients only need a read-only copy.
3) The actual mailing needs the Outlook library. The code to send an email will look something like this:
Dim olApp As New Outlook.Application
'Picks up running Outlook application
Dim olMsg As Outlook.MailItem
Dim olRec As Outlook.Recipient
Dim olAtt As Outlook.Attachment
...
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.Subject = ...
.Body = ...
End With
Set olRec = olMsg.Recipients.Add(addr)
olRec.Type = olTo
Set olAtt = olMsg.Attachments.Add(<filepath>, olByValue)
olMsg.Send
This generates the messages and puts them in your Outbox, but doesn't actually force the sending.
4) In Outlook 2007, go to
>Tools >Trust Center >Programmatic Access
and check the first of the three options. This suppresses warnings provided the Windows Security Center thinks your virus protection is valid and up-to-date. (Note that this doesn't apply to earlier versions of Office).
Hope this helps
/Roy MacLean