PDA

View Full Version : Trigger New Task in Outlook



thombill
01-10-2006, 01:48 PM
All, I am trying to trigger a new outlook task from inside Excel. In the past I have used - Application.Dialogs(xlDialogSendMail).Show, to send the document I am working on. What I am trying to do now is to trigger a new task upon Clicking a Button.

Any help is appreciated:dunno

austenr
01-10-2006, 02:50 PM
Try this. It is set up for Lotus notes but can be adapted for Outlook.

Option Explicit
Sub MaillWorkbook()
Dim EmailSubject As String 'Email Subject Line
Dim UserEmail As String 'The email address that is being sent to
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim Subject As String 'The subject string
Dim Attachment As String 'The path to the attachemnt string
Dim Recipient As String 'The Recipient string (or you could use the list)
Dim Recip(10) As Variant 'The Recipient list
Dim BodyText As String 'The body text
Dim SaveIt As Boolean 'Save to sent mail
Dim WasOpen As Integer 'Checking to see if the Mail DB was already
'open to determine if session should be
'closed (0) or left alone (1)
Dim ClipBoard As DataObject 'Data object for getting text from clipboard
UserEmail = InputBox(PROMPT:="Please enter recipient email address")
EmailSubject = InputBox(PROMPT:="Please enter subject line")
Subject = EmailSubject
Recipient = UserEmail 'Copying it to Clipboard
Sheets("Sheet1").Select
Range("A1:z9000").Select
Selection.Copy
Set ClipBoard = New DataObject
ClipBoard.GetFromClipboard
SaveIt = True
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, _
(Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
WasOpen = 1 'Already open for mail
Else
WasOpen = 0
Maildb.OPENMAIL 'This will prompt you for password
End If
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient 'Or use Racip(10) for multiple
MailDoc.Subject = Subject
MailDoc.body = ClipBoard.GetText(1)
MailDoc.SAVEMESSAGEONSEND = SaveIt
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Range("A1").Select
Application.CutCopyMode = False
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set EmbedObj = Nothing
If WasOpen = 1 Then
Set Session = Nothing
ElseIf WasOpen = 0 Then
Session.Close
Set Session = Nothing
End If

MsgBox "The Email was sent successfully!!", vbOKOnly

End Sub

thombill
01-10-2006, 03:01 PM
Austner,
I appreciate the response, however I am trying to do now is to trigger a new outlook task upon Clicking a Button. I can already email with the following code: it is a little simpler than the Lotus version: Application.Dialogs(xlDialogSendMail).Show

Thank you for your input.:)