PDA

View Full Version : Task list in outlook linket to file structere on harddrive



scholer
02-20-2018, 08:04 AM
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

gmayor
02-20-2018, 09:24 PM
How can a task be a Windows folder? You will need to be more specific before it can be determined what is possible.

scholer
02-21-2018, 08:27 AM
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

gmayor
02-22-2018, 12:27 AM
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

scholer
02-24-2018, 10:26 AM
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:

gmayor
02-24-2018, 09:56 PM
:eek: My fault - a silly mistake - the line should have been


If Not oFSO.FolderExists(strPath) Then

and not


If Not oFSO.FileExists(strPath) Then:banghead: