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
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