Page 1 of 2 12 LastLast
Results 1 to 40 of 55

Thread: [RESOLVED] moving mail from sub folder to personal folder

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Resolved [RESOLVED] moving mail from sub folder to personal folder

    Hi there, I am a complete novice to coding and have been trying to construct a piece of code from other bits i have got for Outlook 2000

    I have a rule that moves specific new mail from the inbox to a subfolder and a macro extracts the attachment. This all works great, but now is where the new code comes in! I need the mail in the sub folder to then be moved to a personal folder. As far as i can see rules don't work on subfolders and i've been playing with code and realised i need to declare my own function to get to the personal folder.

    Here is what i have, i can not work out how to adapt the getfolder function to my needs. running as it is i get errors. I'm at that point where i feel like throwing in the towel, i just can't get my head around it! its probably really simple!

    VB Code:
    1. Public Function GetFolder(strFolderPath As String) As MAPIFolder
    2.   ' folder path needs to be something like
    3.   '   "Public Folders\All Public Folders\Company\Sales"
    4.   Dim objApp As Outlook.Application
    5.   Dim objNS As Outlook.NameSpace
    6.   Dim colFolders As Outlook.Folders
    7.   Dim objFolder As Outlook.MAPIFolder
    8.   Dim arrFolders() As String
    9.   Dim I As Long
    10.   On Error Resume Next
    11.  
    12.   strFolderPath = Replace(strFolderPath, "/", "\")
    13.   arrFolders() = Split(strFolderPath, "\")
    14.   Set objApp = CreateObject("Outlook.Application")
    15.   Set objNS = objApp.GetNamespace("MAPI")
    16.   Set objFolder = objNS.Folders.Item(arrFolders(0))
    17.   If Not objFolder Is Nothing Then
    18.     For I = 1 To UBound(arrFolders)
    19.       Set colFolders = objFolder.Folders
    20.       Set objFolder = Nothing
    21.       Set objFolder = colFolders.Item(arrFolders(I))
    22.       If objFolder Is Nothing Then
    23.         Exit For
    24.       End If
    25.     Next
    26.   End If
    27.  
    28.   Set GetFolder = objFolder
    29.   Set colFolders = Nothing
    30.   Set objNS = Nothing
    31.   Set objApp = Nothing
    32. End Function
    33.  
    34. Sub MoveItems()
    35.  
    36. Dim myolAPP As New Outlook.Application
    37. Dim myNameSpace As Outlook.NameSpace
    38. Dim myInbox As Outlook.MAPIFolder
    39. Dim myInputFolder As Outlook.MAPIFolder
    40. Dim myDestFolder As Outlook.MAPIFolder
    41. Dim myItems As Outlook.Items
    42. Set myNameSpace = myolAPP.GetNamespace("MAPI")
    43. Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
    44. Set myInputFolder = myInbox.Folders("test1")
    45. Set myDestFolder = GetFolder("Personal Folders\test2")
    46. Set myItems = myInputFolder.Items
    47. myItems.Move myDestFolder
    48.  
    49. End Sub

    Many thanks for any help.
    Last edited by fox 2; Dec 21st, 2005 at 08:52 AM.

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

    Re: moving mail from sub folder to personal folder

    Welcome to the Forums.

    You should create a Item_Add event for your sbfolder so when the rule runs and moves the item into it it will trigger the event and move the item to your personal folder, which I assume is in another pst file. If so then you need to use the AddStore method to attach the other pst to your session. Then you can navigate to it and move the item into your desired folder. Then maybe parse the attachment or ???
    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
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    thanks for the reply, sounds like it's getting rather complicated, think it's above me now

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

    Re: moving mail from sub folder to personal folder

    I'll try to walk you through it. Give us a simple example and how it is to be handled. Give details if its in the same pst file or different, etc.
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    hi thanks again

    the folder where the mail is moved to by the rule is a subfolder of the Inbox called "test1" This rule works fine.
    A nice bit of code extracts the attachment and saves it on a local drive. this bit works fine.

    Now i want to move the mail in "test1" (the subfolder of inbox) to a personal folder called "test2". Now because this is not a default folder i know i need to use something like the GetFolder method in my forst post, but i just can't seem to get it working.

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

    Re: moving mail from sub folder to personal folder

    Ok, what is the full path of "test2"?
    "test1" is probably something like - "Personal Folders\Inbox\test1".

    Is "test2" under the same "Personal Folders" or a different one? Are you running Outlook in an Exchange server enviroment?
    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
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    test1 = Inbox\test1
    test2 = Personal Folders\test2

    Outlook 2000 and yes its in an exchange server environment

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

    Re: moving mail from sub folder to personal folder

    Ok so Inbox\test1 is your Exchange folder saved on your exchange server. Then the Personal Folders is a local pst file that is already added to your Outlooks session or do we need to add it?
    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
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    test2 already exists and is there every time i start outlook (if that helps???)

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

    Re: moving mail from sub folder to personal folder

    Yes, it does. Now what you need to do is figure out how to know when to run the code to move the test1 emails?

    We can use the AddStore if the pst is not added but this is how to attach to your test2 folder.

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim oApp As Outlook.Application
    3.     Dim oTest1 As Outlook.MAPIFolder
    4.     Dim oTest2 As Outlook.MAPIFolder
    5.     Set oApp = New Outlook.Application
    6.     Set oTest1 = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("test1")
    7.     'In case the pst is not added then this line:
    8.     'oApp.GetNamespace("MAPI").Session.AddStore ("C:\Documents and Settings\Outlook\MyStore.pst")
    9.     Set oTest2 = oApp.GetNamespace("MAPI").Folders("Personal Folders").Folders("test2")
    10. End Sub
    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
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    the location that you specify the add store, is that a common location or will i need to specify the correct path on my pc?

    thanks once again

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    it seems that my personal folders are on a shared drive

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

    Re: moving mail from sub folder to personal folder

    Thats ok as long as you have permissions to it and its available. Just make sur the "Personal Folders" is reflected as it shows in your Outlook session. If you added it and pointed it to the shared drive then it should be ok, just maybe a bit slower from the network.
    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

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    ok thats done but i get object doesn't support this property or method when i run it

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

    Re: moving mail from sub folder to personal folder

    What line?
    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

  16. #16

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    doesnt say?!?
    am i being stupid??

    shall i take out the bits of code i have done (the ones in the first post)?

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

    Re: moving mail from sub folder to personal folder

    Oh, just try my code in a new test project and add a reference to Outlook. Once we get that working then we can integrate it into your code.
    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

  18. #18

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    ok done. no errors but i dont see it doing anything, is this right?

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

    Re: moving mail from sub folder to personal folder

    Yes, that is true but at least no errors. Add these lines to the end of my code before the End Sub.
    VB Code:
    1. Dim oEmail As Outlook.MailItem
    2.     Set oEmail = oApp.CreateItem(olMailItem)
    3.     oEmail.Move oTest2
    After you run it you should see a new blank email message in the test2 folder. Then it wil be working correctly.
    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

  20. #20

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    ohhh impressive! lol easily pleased! yup that works

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

    Re: moving mail from sub folder to personal folder

    The rest will be just integrating the code logic into your previous code. But how will it know when to run if your doing actions on an item from the rule? Are you going to make this run from a button click or something?

    Sorry but I got to get back to sleep. Almost 4 am. I'll be back tomorrow and will check it out if no one else can help finish the integration.

    Later
    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

  22. #22

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    it runs constantly from new mail so hoping that it will pick it up when it hits test1? if this is possible?

    You are a star! thats such a big help i've been trying to get half this far for over a week!

    ty so much

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

    Re: moving mail from sub folder to personal folder

    Still here. I think you may get into trouble if the rule is running parsing the attachment and then this code runs to move the item. Couldnt you add this from your existing rule maybe?
    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

  24. #24

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    is there a run script part to a rule? or would i need to make my own rule up in vba and let the whole thing run in one block of code when a new mail arrives?

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

    Re: moving mail from sub folder to personal folder

    You can do it all from VBA code like I wrote. You would create an Item_Add event so when you recieve a new email you can test for if you should move it and do your parsing, moving et. But there is a run scrit otpion in a rule but its for a script file I believe. I dont use rules, only vba code so I am not 100% sure.
    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

  26. #26

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    ok i'll take a look and let u know! many thanks
    Now get some sleep!

  27. #27

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    right i changed a couple of lines and this looked right but every time i run it i get object doesn't support property or method error!

    if this bit works i can add it to my other code and try running the whole lot.

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim oApp As Outlook.Application
    3.     Dim oTest1 As Outlook.MAPIFolder
    4.     Dim oTest2 As Outlook.MAPIFolder
    5.     Set oApp = New Outlook.Application
    6.     Set oTest1 = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("test1")
    7.     'In case the pst is not added then this line:
    8.     'oApp.GetNamespace("MAPI").Session.AddStore ("C:\")
    9.     Set oTest2 = oApp.GetNamespace("MAPI").Folders("Personal Folders").Folders("test2")
    10.     Dim oEmail As Object
    11.     Set oEmail = oTest1.Items
    12.     oEmail.Move oTest2
    13. End Sub

    Thanks in advance

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

    Re: moving mail from sub folder to personal folder

    Place a breakpoint on the procedures "Private Sub" line. Then press F8 to step through the code. Tell me which line is generating the error. I am running Outlook 2003 and maybe there is a prop or method that is not in Outlook 2000.
    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

  29. #29

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    everyline seems ok apart from when i get to the end and i press f8 for the lst time so it should jump to end Sub but it gives me the error message

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

    Re: moving mail from sub folder to personal folder

    What was the error message? So is this line executing correct and moving the email?

    oEmail.Move oTest2
    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

  31. #31

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    Yes that line seems fine it's not moving the mail but no errors!

    the error is = runtime error438 object doesn't support this method or property

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

    Re: moving mail from sub folder to personal folder

    Can you post your current code?
    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

  33. #33

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim oApp As Outlook.Application
    3.     Dim oTest1 As Outlook.MAPIFolder
    4.     Dim oTest2 As Outlook.MAPIFolder
    5.     Set oApp = New Outlook.Application
    6.     Set oTest1 = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("test1")
    7.     'In case the pst is not added then this line:
    8.     'oApp.GetNamespace("MAPI").Session.AddStore ("C:\")
    9.     Set oTest2 = oApp.GetNamespace("MAPI").Folders("Personal Folders").Folders("test2")
    10.     Dim oEmail As Object
    11.     Set oEmail = oTest1.Items
    12.     oEmail.Move oTest2
    13. End Sub

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

    Re: moving mail from sub folder to personal folder

    Ok, I see whats happoening here. You didnt add the second line of code that I gave you to create the email object. These are the lines of importance.
    VB Code:
    1. Dim oEmail As Outlook.MailItem
    2.     Set oEmail = oApp.CreateItem(olMailItem)
    3.     oEmail.Move oTest2
    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

  35. #35

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    sorry but are we at cross purposes?? lol
    it's not a new mail im trying to create but move existing new mail from test1 to test2
    i thought the create mail bit just created a blank mail

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

    Re: moving mail from sub folder to personal folder

    Oh, thats right. Then we need to "find" the email in question in the test1 folder and set oEmail = to it. then the move will work.
    VB Code:
    1. Dim oEmail As Outlook.MailItem
    2. Set oEmail = oTest1.Items(oTest1.Items.Count)' Will work if your desired email is the last one in the list, sorted by date/time received
    3. oEmail.Move oTest2
    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

  37. #37

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    ok so what if i want to move all mail from test1 to test2?
    lol getting complicated!

    thanks once again

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

    Re: moving mail from sub folder to personal folder

    Oh, that actually makes things easier. This is not hard at all after you see whats going on.
    VB Code:
    1. Dim oEmail As Outlook.MailItem
    2. Dim i As Integer
    3. For i = 1 To oTest1.Items.Count
    4.     Set oEmail = oTest1.Items(i)
    5.     oEmail.Move oTest2
    6.     Set oEmail = Nothing
    7. Next
    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

  39. #39

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Re: moving mail from sub folder to personal folder

    oops i get array of index out of bounds error

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

    Re: moving mail from sub folder to personal folder

    Sorry, I have been typing directly into the reply box. I doublechecked the code in the VB IDE and it should be...
    VB Code:
    1. Set oEmail = oTest1.Items.Item(i)
    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

Page 1 of 2 12 LastLast

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