• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 794
  • Last Modified:

Adding an Task Item to a public folder with VBA

 I have a section of code that will add a task to a give users task list in outlook..... but I can not figure out how to add the same task to a task list in a public folder.  I need the task to be added to:  "Public Folders\All Public Folders\ProjectTest".   Any help would be greatly appreciated.  Thanks.
Dim objoutlook As Object
    Dim oNameSpace As Object
    Dim oSpDesk As Object
    Dim oFolder As Object
    Dim objtask As Object
    
     Set objoutlook = CreateObject("Outlook.Application")

    Set oNameSpace = objoutlook.GetNamespace("MAPI")
    Set oSpDesk = oNameSpace.CreateRecipient("Blow, Joe")
    Set oFolder = oNameSpace.GetSharedDefaultFolder(oSpDesk, 13)   '13 = olFolderTasks
    Set objtask = oFolder.Items.Add
        objtask.Subject = "Flow Test"
        objtask.DueDate = CDate("12/30/2009")
        objtask.ReminderSet = True
    objtask.Save

Open in new window

0
HelpMePlease777
Asked:
HelpMePlease777
  • 2
1 Solution
 
David LeeCommented:
Hi, HelpMePlease777.

To add a task to a public folder you simply need to get the public folder object and then add the task to it as you do on line 12.  The code below will return a folder based on an Outlook folder path.  For example

    Set objFolder = OpenOutlookFolder("Public Folders\Projects\Project 1")
    Set objtask = objFolder.Items.Add
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    ' Purpose: Opens an Outlook folder from a folder path.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        bolBeyondRoot As Boolean
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Open in new window

0
 
HelpMePlease777Author Commented:
Thanks
0
 
David LeeCommented:
You're welcome.  Happy New Year!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now