PDA

View Full Version : Import custom Outlook 2010 tasks from Excel 2010 using VBA



albidrez
11-20-2013, 08:24 PM
I have a list of tasks in an Excel worksheet that includes custom fields that have already been created in Outlook. As an example, I have a custom task field named Project. I would like to import these tasks into Outlook. I keep getting the
Run-time error '91': Object variable or With block variable not set error. I have the following code:


Sub Test2()
Dim olApp As Outlook.Application
Dim olTask As Outlook.TaskItem
Dim olItem As Object
Dim myFields As Outlook.UserProperty

' Select cell A2, *first line of data*.
Range("A2").Select

' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
Set olApp = New Outlook.Application
Set olTask = olApp.CreateItem(olTaskItem)



With olTask

.UserProperties.Find("Project", True) = Cells(ActiveCell.Row, 2)
'.Subject = Cells(ActiveCell.Row, 5)
.Save
End With

Set olTask = Nothing
Set olApp = Nothing
'Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select

Loop



End Sub


Any thoughts or ideas are welcome. Snarky comments are not. Please assume I've done my very best to search for answers before posting. Thank you!

Patricia

snb
11-21-2013, 01:53 AM
Have a look over here:

http://www.snb-vba.eu/VBA_Outlook_external_en.html#L91