How would you get around “regular occurences” not exporting from an outlook calendar when using vba to export?

I regularly export an outlook calendar from a shared account to a CSV file which is incorporated into an excel dashboard. I want to set up a macro that automatically carries out this export on a daily or weekly basis, so I started by trying to just get a code that carries out the export. I managed to get a VBA code working with the help of MS copilot which exports a CSV file, however it only seems to fully populate the calendar from 2012 for a couple of years, there are inputs from the last couple of years, but not the full daily calendar as it usually exports through the import/ export wizard. I notice that when it is done manually, you are prompted about date ranges and recurring instances being incompatible with CSV, is this something that cannot be done without the wizard compiling it?

I did edit it to only export the current year from the calendar, however the CSV file only had 5 rows populated, which when carried out through the export wizard has the full daily calendar and a subject on each day. Any help or guidance would be appreciated.

The code I currently have working is below:


Sub ExportSpecificCalendarToCSV()

    Dim olApp As Outlook.Application
    
    Dim olNamespace As Outlook.NameSpace
    
    Dim olFolder As Outlook.MAPIFolder
    
    Dim olItems As Outlook.Items
    
    Dim olItem As Object
    
    Dim csvFile As String
    
    Dim output As String
    
    Dim calendarName As String
    
    Dim emailAddress As String
    
    Dim currentYear As Integer
    
    
    
    ' Initialize Outlook application
    
    Set olApp = New Outlook.Application
    
    Set olNamespace = olApp.GetNamespace("MAPI")
    
    
    
    ' Specify the calendar name and email address
    
    calendarName = "On Call Engineer" ' Change this to the name of your calendar
    
    emailAddress = "*** Email address is removed for privacy ***,uk" ' Change this to your email address
    
    
    
    ' Get the specific calendar folder
    
    On Error Resume Next
    
    Set olFolder = olNamespace.Folders(emailAddress).Folders("Calendar").Folders(calendarName)
    
    On Error GoTo 0
    
    
    
    ' Check if the folder exists
    
    If olFolder Is Nothing Then
    
        MsgBox "Calendar not found!", vbExclamation, "Error"
    
        Exit Sub
    
    End If
    
    
    
    Set olItems = olFolder.Items
    
    
    
    ' Sort items by start date
    
    olItems.Sort "[Start]"
    
    
    
    ' Set the CSV file path
    
    csvFile = Environ("USERPROFILE") & "DesktopExam dates on shift OUTLOOK calendar.csv"
    
    
    
    ' Create CSV header
    
    output = "Subject,Start Date,Start Time,End Date,End Time,Location,Body" & vbCrLf
    
    
    
    ' Get the current year
    
    currentYear = Year(Date)
    
    
    
    ' Loop through calendar items
    
    For Each olItem In olItems
    
        If TypeName(olItem) = "AppointmentItem" Then
    
            If Year(olItem.Start) = currentYear Then
    
                output = output & Chr(34) & olItem.Subject & Chr(34) & "," & _
    
                         Format(olItem.Start, "yyyy-mm-dd") & "," & _
    
                         Format(olItem.Start, "hh:mm AM/PM") & "," & _
    
                         Format(olItem.End, "yyyy-mm-dd") & "," & _
    
                         Format(olItem.End, "hh:mm AM/PM") & "," & _
    
                         Chr(34) & olItem.Location & Chr(34) & "," & _
    
                         Chr(34) & Replace(olItem.Body, vbCrLf, " ") & Chr(34) & vbCrLf
    
            End If
    
        End If
    
    Next olItem
    
    
    
    ' Write to CSV file
    
    Dim fileNum As Integer
    
    fileNum = FreeFile
    
    Open csvFile For Output As #fileNum
    
    Print #fileNum, output
    
    Close #fileNum
    
    
    
    ' Notify user
    
    MsgBox "Calendar exported to " & csvFile, vbInformation, "Export Complete"

End Sub

New contributor

Joe Eason is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật