View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
John Google John Google is offline
external usenet poster
 
Posts: 18
Default Creating an Outlook Task Item

Hi,

Excel and Outlook XP version.

I copied the code from the samples.xls workbook that is in the Excel
\Samples directory to create an Outlook task item from excel. I place
a button on a sheet which calls the following macro when clicked:


Sub Button1_Click()
'For this example click References on the Tools Menu, and select the
'Microsoft Outlook 10.0 object libraries.

Dim ol As Object, myItem As Object
'Create a Microsoft Outlook session
Set ol = CreateObject("outlook.application")
'Create a task
Set myItem = ol.CreateItem(olTaskItem)
'Add information to the new task
With myItem
.Subject = "New VBA task XX"
.Body = "This task was created via Automation from Microsoft
Excel XX"
.NoAging = True
.Close (olSave)
End With
'Remove object from memory
Set ol = Nothing

End Sub

When I click the button while Outlook is open it creates an email
message in the Drafts folder. When I click the button when Outlook is
not running, the cursor changes to an hour glass for a couple of
seconds (as it created the Outlook object) however, in this case, when
I start Outlook nothing is there initially but then, after 10-20
seconds an email is placed in my Inbox with the details above. So,
Outlook is creating emails rather than a task!

I've searched the group and found the following post which is slightly
different.


Sub CreateTask()


Dim olApp As Outlook.Application
Dim olTsk As TaskItem


Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)


With olTsk
.Subject = Range("A1")
.Status = olTaskInProgress
.Importance = olImportanceHigh
.DueDate = Range("A2")
.TotalWork = 40
.ActualWork = 20
.Save
End With


Set olTsk = Nothing
Set olApp = Nothing


End Sub


However, this will not compile / run with the error 'User defined type
not defined' for the Outlook.Application type..

In Tools - References 'Microsoft Office 10.0 Object Library' is
selected.


Does anyone know what my problem is or know of a way to do this
successfully?


Thanks for any help.


John.