Outlook Public Calendar VBA

landnw@gmail.com

New member
Local time
Yesterday, 16:06
Joined
Apr 12, 2017
Messages
2
I am trying to link an Outlook public calendar to a button on a form that opens that specific calendar. I am opening the file based on the Entry ID, however, once Outlook is closed, and I attempt to reopen the calendar via the button, it won't work.

Here is the code I used to find the Entry ID:
Private Sub FolderPicker_Click()
Dim olfolder As Outlook.MAPIFolder
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Set olfolder = olapp.GetNamespace("MAPI").PickFolder
olfolder.Display
Debug.Print olfolder.EntryID
Set olfolder = Nothing
Set olapp = Nothing
End Sub

I then use the Entry ID in the following code:
Private Sub GetFolderFromID_Click()
Dim olfolder As Outlook.MAPIFolder
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A0300F46D37F3A6D9214C8EE72B344E69DDAF0000368A08CF0000")
olfolder.Display
Set olfolder = Nothing
Set olapp = Nothing
End Sub

It works fine if I run the first set of code first, and then click the button to open the Calendar. However, if I close the database, or close Outlook, the code errors out on the "set olfolder" line. It's like it doesn't know where its trying to point to. Any help would be greatly appreciated.
 
Hi

When Outlook is running CreateObject uses it.
When its not running you need to use GetObject instead as follows

Code:
If IsAppRunning("Outlook.Application") = True Then
    'Use existing instance of Outlook
    Set objOutlook = CreateObject("Outlook.Application")
Else
   'Could not get instance of Outlook, so create a new one
        Path = GetAppExePath("outlook.exe")    'determine outlook's installation path
        Shell (Path), vbMinimizedFocus   'start outlook
        Do While Not IsAppRunning("Outlook.Application")
            DoEvents
        Loop
        Set objOutlook = GetObject(, "Outlook.Application") 'Bind to new instance of Outlook
        StartOutlookFlag = True 'needed so Outlook can be closed later
End If

CreateObject / GetObject should also be used in this way for linking to Excel / Word etc

If you wish to use the above code it includes 2 functions written by Daniel Pineault: IsAppRunning / GetAppExePath
These are freely available for use from his website www.cardaconsultants.com &
can be adapted as long as his copyright notice is left unchanged.
However it prohibits me from posting the functions on other sites such as this

If you don't want to use them, you should be able to write your own functions to do the same thing
 

Users who are viewing this thread

Back
Top Bottom