Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

I am looking for VB code that I could add to a macro that would export a calendar item from my Inbox.

I am getting calendars shared to me and copying them to my inbox.
Now I need to export them to an excel file using a macro so I can set it up to auto run monthly.
Any Ideas would be appreciated
0
Mswetsky
Asked:
Mswetsky
  • 3
  • 2
1 Solution
 
David LeeCommented:
Hi, Mswetsky.

Are all the calendars exported to a single file, or do they go in separate files?  What fields of each appointment do you need to have exported?
0
 
MswetskyAuthor Commented:
I followed the steps to manually export the calendar and it exported a lot of fields. I need to track events and durations for a group of 8-10 people but am not sure exactly which fields I will be using yet.
0
 
David LeeCommented:
Ok.  This is a script I wrote for another question that should work for what you've described.  You can edit the script to export whatever fields you ultimately decide you need.

Usage will be something like this

    ExportCalendar Session.GetDefaultFolder(olFolderCalendar).Folders("John's Calendar"), "C:\MyCalendar.csv", #10,1/2008#, #10/31/2008#

This would export all appointments in October 2008 from a calendar named "John's Calendar" that's under your calendar to a comma separated values file named MyCalendar.csv
Sub ExportCalendar(olkFolder As Outlook.MAPIFolder, strFileName As String, datStart As Date, datEnd As Date)
    Dim objFSO As Object, _
        objFile As Object, _
        olkItems As Outlook.Items, _
        olkItem As Outlook.AppointmentItem, _
        strBuffer As String, _
        datMyStart As Date, _
        datMyEnd As Date, _
        qt As String
    qt = Chr(34)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile(strFileName, True)
    Set olkItems = olkFolder.Items
    olkItems.Sort "[Start]"
    olkItems.IncludeRecurrences = True
    datMyStart = VBA.Format(datStart, "Short Date")
    datMyEnd = VBA.Format(datEnd, "Short Date")
    Set olkItem = olkItems.Find("[Start] >= """ & datMyStart & """ and [Start] <= """ & datMyEnd & """")
    'Modify the header line to reflect all the values being written
    objFile.WriteLine "Subject,Start,End"
    While TypeName(olkItem) <> "Nothing"
        With olkItem
            'The first value has to be written with a command like this
            strBuffer = qt & .Subject & qt & ","
            'Each subsequent value has to be written with a line like this
            strBuffer = strBuffer & qt & .Start & qt & ","
            'The final value has to be written with a line like this
            strBuffer = strBuffer & qt & .End & qt
        End With
        objFile.WriteLine strBuffer
        strBuffer = ""
        Set olkItem = olkItems.FindNext
    Wend
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing
    Set olkItem = Nothing
    Set olkProp = Nothing
End Sub

Open in new window

0
 
MswetskyAuthor Commented:
This is just what the dr ordered ,
Thank you
0
 
David LeeCommented:
You're welcome.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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