Consulting

Results 1 to 6 of 6

Thread: Task list in outlook linket to file structere on harddrive

  1. #1
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    3
    Location

    Task list in outlook linket to file structere on harddrive

    Hello i am stuck

    I amlooking for a macro that can help with updating my task list from filestructure on harddrive
    So my tasksin outlook will be the folders in a specified location on the harddrive
    The macro will run when outlook opens

    Can anyonehelp me? thanks

  2. #2
    How can a task be a Windows folder? You will need to be more specific before it can be determined what is possible.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    3
    Location
    Sorry i was not specific.

    I have afolder on my hardrive located:
    C:\Users\bruger\Leif Pedersens. Eftf ApS\Team site -General\LPE\2. Tilbudssager\x. Afleverede tilbud

    In that folderi have x number of folder with names example:
    Project 1
    Project 2
    Project 3

    So what I wantis to have my tasks in outlook be like: Project 1, Project 2 etc.
    And when there is a new folder the macro will opdate my task list. So when I create a folder with the name project 4, the task project 4 will apper in outlook

  4. #4
    There is no mechanism in Outlook that will determine if there has been a change to the folder structure on your hard drive in real time. The only possibility is to run an Outlook macro from time to time to examine your folder structure and determine whether there is a task with a subject of the same name in the tasks collection. That part is simple enough. However if there is not such a folder where expected then what information do you want associated with the task subject? The following merely creates a new task with the subject of the project folder name. If you want more information you will have to add-it.

    Sub AddProjectToTasks()
    Dim oFSO As Object, oSourceFolder As Object, oSubFolder As Object
    Dim olNS As NameSpace
    Dim olFldr As MAPIFolder
    Dim olTask As TaskItem, olNewTask As TaskItem
    Dim oCol As New Collection
    Dim lngIndex As Long
    Dim bFound As Boolean
    Const strPath As String = "C:\Users\bruger\Leif Pedersens. Eftf ApS\Team site -General\LPE\2. Tilbudssager\x. Afleverede tilbud\"
    
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        If Not oFSO.FileExists(strPath) Then
            MsgBox "Følgende mappe er ikke tilgængelig" & vbCr & vbCr & strPath
            GoTo lbl_Exit
        End If
        Set olNS = GetNamespace("MAPI")
        Set olFldr = olNS.GetDefaultFolder(olFolderTasks)
        For Each olTask In olFldr.Items
            If LCase(olTask.Subject) Like "project*" Then
                oCol.Add olTask.Subject
            End If
        Next olTask
        Set oSourceFolder = oFSO.GetFolder(strPath)
        For Each oSubFolder In oSourceFolder.SubFolders
            bFound = False
            If LCase(oSubFolder.Name) Like "project*" Then
                If oCol.Count > 0 Then
                    For lngIndex = 1 To oCol.Count
                        If LCase(oSubFolder.Name) = LCase(oCol(lngIndex)) Then
                            bFound = True
                            Exit For
                        End If
                    Next lngIndex
                End If
                If Not bFound Then
                    Set olNewTask = CreateItem(olTaskItem)
                    With olNewTask
                        .Subject = oSubFolder.Name
                        .Close (olSave)
                    End With
                End If
            End If
        Next oSubFolder
    lbl_Exit:
        Set oFSO = Nothing
        Set oSourceFolder = Nothing
        Set oSubFolder = Nothing
        Set olNS = Nothing
        Set olFldr = Nothing
        Set olTask = Nothing
        Set olNewTask = Nothing
        Set oCol = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    3
    Location
    Perfect..

    It is just what i need.

    But i can´tget it to work
    I just keep getting the msgbox with “følgende mappeeksistere ikke”
    Even if ichange the path to just be c:

  6. #6
    My fault - a silly mistake - the line should have been

    If Not oFSO.FolderExists(strPath) Then
    and not

    If Not oFSO.FileExists(strPath) Then
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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