Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

How to locate a subscribed internet calendar's folder path in Excel VBA with Namespace Outlook Object?

$
0
0

I am trying to get my code to list the events of a subscribed internet calendar from gmail. Currently the code does its job but only lists events created in the outlook app in the Calender Folder.

Here is the current code I found on Stack Overflow:

Option Explicit

Sub ListAppointments()
  Dim olApp As Object
  Dim olNS As Object
  Dim olFolder As Object
  Dim olApt As Object
  Dim NextRow As Long
  Dim FromDate As Date
  Dim ToDate As Date

FromDate = CDate("08/25/2018")
ToDate = CDate("12/31/2019")

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0

Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(9) 'olFolderCalendar 9
NextRow = 2


With Sheets("Sheet1") 'Change the name of the sheet here
    .Range("A1:D1").Value = Array("Project", "Date", "Time spent", "Location")
    For Each olApt In olFolder.Items
        If (olApt.Start >= FromDate And olApt.Start <= ToDate) Then
            .Cells(NextRow, "A").Value = olApt.Subject
            .Cells(NextRow, "B").Value = CDate(olApt.Start)
            .Cells(NextRow, "C").Value = olApt.End - olApt.Start
            .Cells(NextRow, "C").NumberFormat = "HH:MM:SS"
            .Cells(NextRow, "D").Value = olApt.Location
            .Cells(NextRow, "E").Value = olApt.Categories
            NextRow = NextRow + 1
        Else
        End If
    Next olApt
    .Columns.AutoFit
End With

Set olApt = Nothing
Set olFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing

End Sub

I am almost positive that the issue lies here:

Set olFolder = olNS.GetDefaultFolder(9) 'olFolderCalendar 9

The folder name I want to access is basic, I have tried using both these:

Set olFolder = olNS.GetDefaultFolder(9).Folders("basic").Items
  Set olFolder = olNS.GetDefaultFolder(9).Parent.Folders("basic").Items

And none of these worked. Run-time error '-2147221233 (8004010f)': The Attempted operation failed. An Object Could Not Be Found. Here is the basic folder I want to grab the events from.

EDIT: Okay, so this is what I ultimately found: olNS.GetDefaultFolder(9).Parent = email@gmail.com and Its Child is one of my calendars "Calendar" seen in the picture. The parent of "basic" calendar is Internet Calendars. How can I set olFolder to the directory '\Internet Calendars\basic' instead of '\email@gmail.com\Calendar'

Thank you


Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>