dcsimg
Results 1 to 6 of 6

Thread: Outlook 2003 - create VBA code that automates "Import Export Wizard"

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    3

    Outlook 2003 - create VBA code that automates "Import Export Wizard"

    I regularly export my MS Outlook "Calendar" using the "Import Export Wizard" to a 'Windows' compatible csv file, so that it can be imported into Google Calendar.
    Has anybody written any VBA code that ploughs through the numerous dialog boxes to achieve this please?
    Is there a function, albeit with numerous arguments, that can be invoked to carry out this routine proceedure insead of wading repetatively through the wizard?

    I have been programming in VBA since Excel v5, and Access v2 and understand the concept of Objects, Methods & Properties; automating many tedious repetative tasks I do daily. However, Outlook has me defeated, having looked at the Outlook application Object Model I'm dumbfounded as to where to begin!

    So far I have progressed this far!

    olvba_01.doc

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,778

    Re: Outlook 2003 - create VBA code that automates "Import Export Wizard"

    i do not know about automating the wizard, but it would be easy enough to write the calendar data out to a csv or other file in the required format

    Code:
    Dim c As MAPIFolder, itm As AppointmentItem
    Set c = ThisOutlookSession.GetNamespace("mapi").GetDefaultFolder(olFolderCalendar)
    f = FreeFile
    Open "c:/temp/myfile.csv" For Output As f
    For Each itm In c.Items
        Print #f, itm.subject & "," & itm.Start & "," & itm.End
    Next
    Close f
    this is an example only, you would need to put the itm properties required into the correct order for google to import, also some special handling may be required for recurring appointments, change path and filename to suit, the file will be overwritten each time
    you should inspect an exported csv file to find what data is required in the file
    it would also be possible to only export items that match some criterias
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    3

    Re: Outlook 2003 - create VBA code that automates "Import Export Wizard"

    Thanks for that, I guessed it would end up with involving a loop through a list if ‘Items’ in a ‘Collection’. I have pasted your code and changed the path & filename, and run the code.
    It creates a csv file but of course only the ‘Subject’, ‘Start’ & ‘End’ fields are created.

    As you can see from the screen shot in the attached “VBA Export Calendar code.doc” there are currently 273 items in the Calendar.

    I’ve also attached an Excel file: “outlook calendar.xls”, created from the inbuilt "Import Export Wizard" (with the resultant csv file saved as an xls file to preserve formatting), which shows;
    1. that there is a header row included to ensure fields are mapped correctly. This does not occur in your code; see: “myfileCalendar.xls” – attached (the csv file opened in Excel and saved as an .xls file to preserve formatting).
    2. there are 22 Fields created from “Subject” to” Show time as” when the wizard is used.
    3. I created a small number of entries in “outlook calendar.xls” as I limited the date period the wizard offers to 4 days, rather than show all entries for the 273 items to keep the file size small. Usually the period is 3 months, or whatever you enter into the final wizard dialog box.

    Interestingly, I extended the following code line in your suggestion from:

    Print #f, itm.subject & "," & itm.Start & "," & itm.End

    To:

    Print #f, itm.subject & "," & itm.Start_Date & "," & itm.Start_Time & "," _
    & itm.End_Date & "," & itm.End_Time

    to try and map the fields that the wizard produces, but this fails with a dialog box error message:
    “Run time error ‘438’ – Object doesn’t support this property or method”.

    Hmmmm…. !!!

    I've tried uploading 2 other files but your system says they are invalid files!
    How do I attach .csv & .xls files?
    Attached Files Attached Files

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    3

    Re: Outlook 2003 - create VBA code that automates "Import Export Wizard"

    Seems you can't attach .csv & .xls files!

    So have done screen shots of files and attached here as a .doc
    Attached Files Attached Files

  5. #5
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,290

    Re: Outlook 2003 - create VBA code that automates "Import Export Wizard"

    Hi,

    if you have Access it might be of intrest that you can Link Outlook Folders (Contacts ... etc..)

    here a discription.. https://support.office.com/en-us/art...d-83590c2085a3

    then you have a Table in your Database for Exporting

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,778

    Re: Outlook 2003 - create VBA code that automates "Import Export Wizard"

    How do I attach .csv & .xls files?
    zip first
    As you can see from the screen shot in the attached
    i can not really see anything at all in your word documents

    1. it is not difficult to add a header row, immediately after opening the file for output, you could just copy and paste the top row from one the existing files, you can then match the values from each itm in the order of the headers

    Print #f, itm.subject & "," & itm.Start_Date & "," & itm.Start_Time & "," _
    & itm.End_Date & "," & itm.End_Time
    itm.start_date etc do not exist as properties, itm.start and itm.end both are date /time values, but you can return both the date and time as separate values from each, you could also calculate the duration of the task if you need that

    2. i have no idea of show time As, some fields may be easier to either omit or if the values are consistant, just copy from an existing export
    as i do not know the correct output format or the exported file i can only make suggestions

    3. you can use the restrict method of the items collection to just get the required items, by date and various other criteria
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width