Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
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.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Creating an Outlook Task Item

I've solved it myself. I found another post are realised that I had to
add a reference for the 'Microsoft Outlook 10.0 Object Librarry' as
well as 'Microsoft Office 10.0 Object Library'.

I should have read the comments clearly!!!!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Creating an Outlook Task Item

I've hit another problem. I use the code:

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

In A2 is have a date 14/04/2008 (UK date format DD/MM/YYYY). When I
look at it in Outlook Tasks it shows the date as 30/12/1899. This is
the same date in Outlook for various dates in the 2007 - 2008 range.

I'm assuming Outlook and Excel use different date format. Is there a
way to convert between the two? What are the rules?

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Creating an Outlook Task Item

Solved!

The cell A2 was empty so it returned 0 which is one day before
01/01/1900.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Task information from Excel to Outlook scott56hannah Excel Discussion (Misc queries) 1 October 7th 07 03:15 PM
Creating a task in Outlook from a date in Excel Jamie@Wildcard Excel Discussion (Misc queries) 3 July 3rd 07 04:54 PM
How can i have Excel automatically set an Outlook task? VT Excel Discussion (Misc queries) 0 July 31st 06 11:49 AM
Grrrhhhh..Outlook task form Chris-John Turner Excel Discussion (Misc queries) 1 August 23rd 05 04:07 AM
Importing task description to outlook P.hamsa Excel Discussion (Misc queries) 1 February 28th 05 05:33 PM


All times are GMT +1. The time now is 01:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"