Results 1 to 14 of 14

Thread: Outlook: Copy a Task to another Task Folder

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Question Outlook: Copy a Task to another Task Folder

    Hi!

    I've been trying to find an answer to my problem for a while and still have no clue about it... Perhaps anybody here would be able to help me??

    Information: I work with Outlook 2003 and Public ShareFolder v1.2
    To make it simple Public SF is an application allowing all Outlook "clients" of a small network to acess the Outlook server's .pst files...

    My problem:
    From my Outlook "client" I can manually copy tasks from the client's task folder to the server's task folder.
    I'd would like to do it automatically with a macro... But i'm not sure it's possible

    thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    Welcome to the Forums.

    You would need to access the Item in the source MAPI folder and then create a reference to the destination MAPI folder. Then just invoke the .Copy method on each item in the source folder in a loop. This program "Public ShareFolder v1.2" create several pst files or a single one?

    This will work (maybe an error since I typed it into the reply box ) but if the public destination folder is in another pst file then it may require some extra code.

    VB Code:
    1. dim oApp as outlook.application
    2. dim oNS as outlook.namespace
    3. dim oTasks as outlook.mapifolder
    4. dim oPublicFolders as outlook.mapifolder
    5. dim oPublicTasks aas outlook.mapifolder
    6. dim i as integer
    7.  
    8. set oapp = new outlook.application
    9. set ons = oapp.getnamespace("MAPI")
    10. set otasks = ons.getdefaultfolder(olfoldertasks)
    11. set opublicfolders = ons.getdefaultfolder(olpublicfoldersallpublicfolders)
    12. set opublictasks = opublicfolders.folders("all public folders").folders("TasksCopy")
    13.  
    14. for i = 1 to otasks.items.count
    15.     otasks.items(i).copy opublictasks
    16. next
    17.  
    18. 'clean up
    19. set otasks = nothing
    20. set opublictasks = nothing
    21. set opublicfolders = nothing
    22. set ons = nothing
    23. set oapp = nothing
    Last edited by RobDog888; Aug 31st, 2005 at 11:05 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    Hi RobDog!

    Thanks a lot for your help!

    I'll probably need some extra code because the destination folder is indeed inside an other pst files.
    You ask me about Public ShareFolder if it was creating only several files or only a single one. In fact it's not creating a file but I guess it's accessing a remote Outlook.pst on another computer of the network.

    Anyway, I've tested your code on my Outlook to try to copy a task inside another "MAPI" folder but I unfortunately have an execution error: "can't find the object" on the following line :

    Set oPublicFolders = oNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)

    It seems to recognize what "olPublicFoldersAllPublicFolders" is: If I run step to step the macro olPublicFoldersAllPublicFolders contant = 18 but Outlook can't set oPublicFolders. If you have any idea about this error...

    Thanks

    Yann

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    Hi RobDog!

    I guess I've found out what was the problem in your code. I went on the foolowing website to obtain more information about olPublicFoldersAllPublicFolders and GetDefaultFolder. It looks like the method is not allowed to open a couple of folders: one of them is olPublicFoldersAllPublicFolders

    http://msdn.microsoft.com/library/de...HV05247519.asp

    Perhaps do you know (or anybody else on the forum) another way to do it?

    Thanks

    Yann

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    Nope, not the issue. If you read the description and the function name, its a different function. GetDefaultFolder vs. GetSharedDefaultFolder.
    Microsoft Outlook does not allow you to open the following folders using the GetSharedDefaultFolder method. Therefore, the following constants cannot be used with this method:

    Deleted Items - olFolderDeletedItems
    OutBox - olFolderOutbox
    Sent Items - olFolderSentMail
    All Public Folders - olPublicFoldersAllPublicFolders
    As I had mentioned in a previous post, if your destination folder is in another pst file then you need extra code to open the pst and add it to your session. Then you can transverse its folder structure for pasting in the copied task.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    ARRRRG!!! I lost my post to that stupid connection error we have been getting hammered with lately.

    Anyways I will try to repost what I had posted....


    If you are running in an Exchange environment then you will have a Public Folders folder. This is truely public. If you are not running Exchange and only opening another users shared folder then its a Shared folder and not public.

    You need to look at the AddStore and AddStoreEx functions of the NameSpace object in order to add the other pst file to your current Outlook session. After its added then you can tranverse the folder structure to paste your copied task.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    Thanks for your advice!

    I've managed to add the other PST file to my current Outlook session but I still can't access the tasks inside the new folder.
    In fact I don't really know which method or function I have to use to acess items in the new foder...

    I've tried to modified the piece of code you gave me but there is no results until now...

    This is the modified code if you can tell me what's wrong... (I'm not using Exchange so I suppose that's only a Share Folder)
    Thanks

    VB Code:
    1. Sub TaskCopy()
    2.  
    3. Dim oApp As Outlook.Application
    4. Dim oNS As Outlook.NameSpace
    5. Dim oTasks As Outlook.MAPIFolder
    6. Dim oPublicFolders As Outlook.MAPIFolder
    7. Dim oPublicTasks As Outlook.MAPIFolder
    8. Dim i As Integer
    9.  
    10. CreatePST
    11.  
    12. Set oApp = New Outlook.Application
    13. Set oNS = oApp.GetNamespace("MAPI")
    14. Set oTasks = oNS.GetDefaultFolder(olFolderTasks)
    15.  
    16. Set oPublicFolders = oNS.GetSharedDefaultFolder(olFolderTasks)
    17. Set oPublicTasks = oPublicFolders.Folders("NewFolderName")
    18.  
    19. For i = 1 To oTasks.items.Count
    20.     oTasks.items(i).Copy oPublicTasks
    21. Next
    22.  
    23. 'clean up
    24. Set oTasks = Nothing
    25. Set oPublicTasks = Nothing
    26. Set oPublicFolders = Nothing
    27. Set oNS = Nothing
    28. Set oApp = Nothing
    29.  
    30. End Sub
    31.  
    32.  
    33. Sub CreatePST()
    34.  
    35.     Dim myOlApp As New Outlook.Application
    36.     Dim myNameSpace As Outlook.NameSpace
    37.     Set myNameSpace = myOlApp.GetNamespace("MAPI")
    38.     myNameSpace.AddStore "\\serveur\Outlook\Outlook.pst"
    39.  
    40.    
    41. End Sub

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    Why are you still using GetSharedDefaultFolder instead of GetDefaultFolder? I dont see where your opening the store and setting a MAPIFolder object to the destination folder in the store? Aso, your looping and copying tasks but not doing anything with them. So your overwritting the clipboard each time with the next one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    Hi RobDog,

    Why was I Still using GetSharedDefaultFolder instead of GetDefaultFolder?
    Because I thought I had to use it as far as I was using another pst file which was not the current user's file.
    In fact when I use this command: MyNameSpace.AddStore "\\serveur\Outlook\Outlook.pst",
    I suppose I add a new store in the MAPI Folder. As a result I can see a new "Personal Folder" in my mail list window

    Then I need to access items inside this new store but before I've got to call this new folder...
    So my question is : How to named this new folder?
    for instance : MyNewFolder = MyNameSpace.AddStore "\\serveur...." then I could Set MyNewFloder as a new MAPI Object with the GetDefaultFolder method if I'm right!

    I hope my post is clear enough. I'm really sorry for all these questions which can be perhps silly to you but I'm just beginning to understand how Outlook programming is working and the main part is still obscure... but I'm not giving up
    So thank you for your patience

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    Good to hear your not giving up

    Ok, I see what your saying. GetDefaultFolder only works for the top level default folders Outlook create by default - Inbox, Calendar, Tasks, SentItems, etc).


    If the other users folder you want to open in the other users pst is a Default folder then GetSharedDefaultFolder will be ok. If its a custom folder then you need the .Folders collection.

    I'll see if I can write up an example for you later today when I finish my work.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    Hi RobDog!

    I've been trying to find a way to call that folder but I'm still looking for a solution.
    I'm going to make a break with it for a while because I've got one week holidays and I'll be far away from my computer... but I'll be back anyways
    See you then

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    Ok, have a good time. I havent been able to test the Shared folder method since I dont have another user to share from. BUMP the thread when your back.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    a small village lost in the middle of nowhere
    Posts
    7

    Re: Outlook: Copy a Task to another Task Folder

    I really had a good time. Thanks
    That's so pleasant to take a break sometimes...
    Anyway, you told me about the Shared folder method you haven't tested yet? I'm now ready to test it if you want!

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook: Copy a Task to another Task Folder

    The issue is that I am not running in an Exchange environment so its really hard to test without having the share options.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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