Results 1 to 16 of 16

Thread: VBA - Outlook Calender Export

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    VBA - Outlook Calender Export

    Hi All,

    Scenario:
    I want to automate a process to:
    a) export my Outlook 'calender' to a .pst file,
    then I plan to take that file to another PC, and
    b) import it (no duplicates) into the other PC's Outlook (calender).

    Can someone please kick this off with a snippet to export the 'calender' to .pst file?




    Regards,
    Bruce.

  2. #2

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    The start of part a; (base code credit to JordanChris)

    VB Code:
    1. Option Explicit
    2.  
    3. Public Sub Extract_Calender()
    4. Dim NameSpace As Outlook.NameSpace
    5. Dim myCal As Object
    6. Dim myCalItems As Object
    7. Dim myItem As Object
    8.  
    9. On Error GoTo Err_Handler:
    10.  
    11.     Set NameSpace = Outlook.GetNamespace("MAPI")
    12.     Set myCal = NameSpace.GetDefaultFolder(9)
    13.     Set myCalItems = myCal.Items
    14.  
    15.     For Each myItem In myCalItems
    16.         MsgBox "Calendar Item " & _
    17.             myItem.Location & " " & _
    18.             myItem.Subject & " " & _
    19.             myItem.Body & " " & _
    20.             myItem.Start & " " & _
    21.             myItem.End
    22.     Next
    23.  
    24.     Set NameSpace = Nothing
    25.     Set myCal = Nothing
    26.     Set myCalItems = Nothing
    27.    
    28. Exit Sub
    29.  
    30. Err_Handler:
    31.  
    32.     If Not (NameSpace Is Nothing) Then Set NameSpace = Nothing
    33.     If Not (myCal Is Nothing) Then Set myCal = Nothing
    34.     If Not (myCalItems Is Nothing) Then Set myCalItems = Nothing
    35.    
    36.     MsgBox "Description: " & Err.Description & vbCrLf & _
    37.             "Number: " & Err.Number, vbOKOnly + vbInformation, "Extraction Error"
    38.  
    39. End Sub
    Last edited by Bruce Fox; Aug 5th, 2004 at 08:50 PM.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I will create a custome example for you. I have seen others
    asking for this also.

    Be back in a few.
    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

  4. #4

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Thanks Rob,

    I knew you were the man for the job

    I had seen some of your similar posts, but couldn't find much on Calendar.
    For what its worth, the above does return all Calendar events (VBA, and in VB)

    I could, if required, extract this into a textfile, then reload as required (using the appropriate fields).

    Thanks for your efforts.



    Bruce.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Almost have it finished. I am approaching it from a different point
    of view. This is going to be fast and good! I think I will use this
    myself too. Couple of minutes more. Had to help my daughter
    with something.
    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

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Thanks Rob,

    Ultimately, its a method of 'syncronising' two different Outlooks without the need of a PocketPc or the like. I thought I'd start off with the Calendar, then maybe the Addressbook (seems to be alot about that).


    Must be getting late for you



    Bruce.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No not too late. What version of Outlook do you run?
    I tested and wrote it on 2003 and no problems. I am currently
    uploading and testing on my system at work which has 2000.
    Then I will post in a couple of minutes.
    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

  8. #8

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    2000 SP 3.

    I off home in a tick, will check when I get home. I will also test when I get back to work on Monday. Many thanks.
    If I dont catch you online tonight; have a great weekend.

    I'm sure it will be helpful, as you know other have asked and there has been no decent response.



    Bruce.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I have finished it for 2000, but for 2003 I have a bug I want to fix
    first. It will be up before monday.

    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

  10. #10

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    For the benifit of others, there is a method that you can do manually thru Outlook, but how handy would it be to have it done automatically.

    The manual method would sort of be like this:
    You would export the calander/addressbook as a .pst file (taking time to make the appropriate selections),
    then once you have this file, you can import it back into Outlook,
    manually making/selecting appropriate selection (ie where to copy it, don't copy duplicates etc). Although pretty much simple, it takes a few mouse clicks and dialog boxes to achieve.

    So, it would be handy to have some (VB/VBA) code to achieve this automatically.
    In my case I will set up my friends PC at work with a button to envoke a macro that will perform the export. Then, with the file now on on a pen drive have a similar button that will envoke a macro to do the import of the file to his home PC - simple



    Bruce.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Bruce, I am a little busy this morning at work to fit in time to finish
    the program, but it is working fine for Outlook 2000 SR-1 running
    on Windows 2000 Terminal Server. I will have more time tonight
    at home.

    BTW, my program is very similar to the manual method.

    I will pm you on something else.
    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

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Bruce, I am back. Here is main part of the solution.

    First, need to add a new pst file with a date/time filename stamp
    using the .AddStoreEx method from the Namespace object for
    2003 else use the .AddStore for 2002 and below with a version
    trap for unsupported version of Outlook.

    Then, use the .GetLast method to set a MAPIFolder object equal
    to the newly added pst file.

    Then iterate through the folders you want to backup by re-
    creating the objects in the pst folder.

    I can email you my program as soon as I finish the last of the
    help file if you want since you inspired me on this utility.

    Ps: hows the weather down in Australia?

    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
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    G'Day RobDog,

    Thanks for the reply.

    I'm now testing on a Palm SizePC (issues detailed on a different post). However, I'll give that ago; watch this space

    Still a bit chilly down this way.
    Seems our guys are doing well in the pool over in Greece.



    Bruce.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is the screenshot of my final product.

    Working on giving it the XP look, but not working yet.




    Later
    Attached Images Attached Images  
    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

  15. #15
    New Member
    Join Date
    Aug 2004
    Posts
    1
    I would be very interested in this as well, if you could post the code in this thread it would be much appreciated!

  16. #16
    New Member
    Join Date
    Aug 2009
    Posts
    1

    Re: VBA - Outlook Calender Export

    hi,
    is it possible to have that macro ? just need to export regularly the calendar to a .pst...

    thks

    fabien

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