Results 1 to 6 of 6

Thread: Outlook code to export tasks - was working - now isn't!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    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?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,913

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Re: Outlook code to export tasks - was working - now isn't!

    Quote Originally Posted by westconn1 View Post
    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
    Code:
    Dim tsk As Variant
    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

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,913

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Re: Outlook code to export tasks - was working - now isn't!

    Any idea how i would solve this?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,913

    Re: Outlook code to export tasks - was working - now isn't!

    see if the object browser can help

    in menu > view (or F2)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width