Outlook code to export tasks - was working - now isn't!
Hi guys. I've got the following code which works just fine - it exports tasks to an excel spreadsheet. I upgraded to outlook 2010 and windows 7 and suddenly it doesn't work on my PC. It does however work on one of my work-colleagues PC - same references and evertyhing.
VBA:
Code:
Sub export_tasks()
'*******************************************************************************************
'******************************DECLARE VARIABLES********************************************
Dim strReport As String
Dim olnameSpace As Outlook.NameSpace
Dim taskFolder As Outlook.MAPIFolder
Dim tasks As Outlook.Items
Dim tsk As Outlook.TaskItem
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Dim sht As Excel.Worksheet
Dim strMyName As String
Dim x As Integer
Dim y As Integer
'*******************************************************************************************
'*****************************REMOVE EXISTING DATA******************************************
Set exWb = objExcel.Workbooks.Open("C:\Tasks.xls")
exWb.Sheets("Sheet1").Range("A1:H2500").Select
exWb.Sheets("Sheet1").Range("A1:H250").ClearContents
'*******************************************************************************************
'*****************************REFERENCE WORKBOOKS*******************************************
Set olnameSpace = Application.GetNamespace("MAPI")
Set taskFolder = olnameSpace.GetDefaultFolder(olFolderTasks)
Set tasks = taskFolder.Items
strReport = ""
'*******************************************************************************************
'*****************************CREATE THE HEADER*********************************************
exWb.Sheets("Sheet1").Cells(1, 1) = "Subject"
exWb.Sheets("Sheet1").Cells(1, 2) = "Start Date"
exWb.Sheets("Sheet1").Cells(1, 3) = "Due Date"
exWb.Sheets("Sheet1").Cells(1, 4) = "Percent Complete"
exWb.Sheets("Sheet1").Cells(1, 5) = "Status"
exWb.Sheets("Sheet1").Cells(1, 6) = "Owner"
exWb.Sheets("Sheet1").Cells(1, 7) = "Requested by"
exWb.Sheets("Sheet1").Cells(1, 8) = "Completed Date"
exWb.Sheets("Sheet1").Cells(1, 10) = "Notes"
y = 2
For x = 1 To tasks.Count
Set tsk = tasks.Item(x)
'*******************************************************************************************
'*****************************FILL IN THE DATA**********************************************
'If the task is not set to private then continue
If Not tsk.Sensitivity = olPrivate Then
'Add the data
exWb.Sheets("Sheet1").Cells(y, 1) = tsk.Subject
exWb.Sheets("Sheet1").Cells(y, 2) = tsk.StartDate
exWb.Sheets("Sheet1").Cells(y, 3) = tsk.DueDate
exWb.Sheets("Sheet1").Cells(y, 4) = tsk.PercentComplete
exWb.Sheets("Sheet1").Cells(y, 5) = tsk.Status
exWb.Sheets("Sheet1").Cells(y, 6) = tsk.Owner
exWb.Sheets("Sheet1").Cells(y, 7) = tsk.Delegator
exWb.Sheets("Sheet1").Cells(y, 8) = tsk.DateCompleted
exWb.Sheets("Sheet1").Cells(y, 10) = tsk.Body
y = y + 1
End If
Next x
'*******************************************************************************************
'******************************SAVE AND CLOSE***********************************************
exWb.Save
exWb.Close
Set exWb = Nothing
End Sub
The error that comes up is 'Run Time Error 13 - Typ mismatch' and highlights
Set tsk = tasks.Item(x)
Can anyone help?
Re: Outlook code to export tasks - was working - now isn't!
try changing tsk to type variant, see if it works, if so then you can find the correct type to use for tsk
Re: Outlook code to export tasks - was working - now isn't!
Quote:
Originally Posted by
westconn1
try changing tsk to type variant, see if it works, if so then you can find the correct type to use for tsk
Thanks for the support
I’ve changed
Code:
Dim tsk As Outlook.TaskItem
To
This produces the following error:
Run-time error 438 – Object doesn’t support this property or method
It then highlights:
exWb.Sheets("Sheet1").Cells(y, 2) = tsk.StartDate
Re: Outlook code to export tasks - was working - now isn't!
it would appear to me that the task item objects have changed in the newer version, they must be of different type and have some different properties and methods
Re: Outlook code to export tasks - was working - now isn't!
Any idea how i would solve this?
Re: Outlook code to export tasks - was working - now isn't!
see if the object browser can help
in menu > view (or F2)