Selecting specific calendar from Excel

Status
Not open for further replies.

Paul Fisher

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
The following code creates an appointment in my default calendar.
How can I change it to select a specific calendar into which to add the appointment? I know the name of the Calendar but not it's Index number which might vary from user to user.

If IDCal = "Yes" Then
With CreateObject("Outlook.Application").CreateItem(1)
.Subject = ID_Time & " / " & Surname & " / " & "ID Visit"
.Start = ID_Date + " " + ID_Time
.Duration = 60
.Location = Client Office
.Save
End With
End If
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
use items.add
Set CalFolder = olNs.GetDefaultFolder(olFolderCalendar)
Set subFolder = CalFolder.Folders("sub folder name")
Set olAppt = subFolder.Items.Add(olAppointmentItem)

if its in a shared folder, you'll need to use the shared folder code at the end of this article - Working with VBA and non-default Outlook Folders to identify it the reference it
Set olAppt = CalendarFolder.Items.Add(olAppointmentItem)
 

Paul Fisher

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
Thanks for your help, I'll try that and see if I can make it work. I am much more familiar with Excel than Outlook so it takes me a while to understand what is happening on the Outlook side.
 

Paul Fisher

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
use items.add
Set CalFolder = olNs.GetDefaultFolder(olFolderCalendar)
Set subFolder = CalFolder.Folders("sub folder name")
Set olAppt = subFolder.Items.Add(olAppointmentItem)

if its in a shared folder, you'll need to use the shared folder code at the end of this article - Working with VBA and non-default Outlook Folders to identify it the reference it
Set olAppt = CalendarFolder.Items.Add(olAppointmentItem)
Diane, many thanks for your help. I am having to use the Late Binding method as I cannot be sure which version of Outlook is running on the PCs. I have adapted my code so that I can now specify a subfolder of the default calendar. As I am self taught, it takes me quite a while to work these things out! However I can't begin to grasp how to access a Shared Folder using this method. Any further help/suggestions would be very much appreciated. My new code is below.

Sub Automateappt()

Dim applOutlook As Object
Dim nsOutlook As Object
Dim cfOutlook As Object
Dim ifOutlook As Object
Dim cffolder As Object
Dim olAppt As Object

Set applOutlook = GetObject(, "Outlook.Application")

Set nsOutlook = applOutlook.GetNamespace("MAPI")

Set cfOutlook = nsOutlook.GetDefaultFolder(9)
MsgBox cfOutlook

Set cffolder = cfOutlook.Folders(1)
MsgBox cffolder

'Set olAppt = applOutlook.CreateItem(1) ' 1 = olAppointmentItem
Set olAppt = cffolder.Items.Add ' this puts it in the correct calendar

With olAppt

.Subject = "Test Appt Subject"
.Start = "13/03/2016 11:45"
.Duration = 60
.Location = "Test Location"
.Save
End With

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This line gets changed:
Set cfOutlook = nsOutlook.GetDefaultFolder(9)

You need to use the shared folder code from Working with VBA and non-default Outlook Folders instead.

Dim objOwner As Outlook.Recipient
Set objOwner = nsOutlook.CreateRecipient("maryc")
objOwner.Resolve

If objOwner.Resolved Then
'MsgBox objOwner.Name
Set cfOutlook = nsOutlook.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
 

Paul Fisher

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
This line gets changed:
Set cfOutlook = nsOutlook.GetDefaultFolder(9)

You need to use the shared folder code from Working with VBA and non-default Outlook Folders instead.

Dim objOwner As Outlook.Recipient
Set objOwner = nsOutlook.CreateRecipient("maryc")
objOwner.Resolve

If objOwner.Resolved Then
'MsgBox objOwner.Name
Set cfOutlook = nsOutlook.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
Diane - many thanks again..... should give me hours of fun to understand and implement your suggestion. Good job I am only doing this as a hobby!
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
K Selecting a folder from an entry in a Listbox Outlook VBA and Custom Forms 1
N Selecting multiple calendar items Using Outlook 4
I Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 0
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
S Creating Email - Selecting Pre-Defined Text Using Outlook 2
S Selecting "Mileage" field on "Detail" page Outlook VBA and Custom Forms 2
RalphG101 No indication of attachment, when selecting file, send to outlook. Using Outlook 0
A Auto Insert of filename when selecting 'Remove Attachment' Using Outlook 1
R VBScript Sendmail not selecting correct 'from' address Outlook VBA and Custom Forms 3
230Grains iCloud COM Module Keeps de-selecting in Outlook 2013 Using Outlook 1
F Automatically close email after selecting mark unread Using Outlook 1
S categories are being cut off after selecting from category pop up form Using Outlook 3
S Outlook Custom form - selecting text in read page Using Outlook 0
V Selecting multiple folders Using Outlook 2
D Selecting shared calendar for appointment/meeting templates Using Outlook 2
B MS Office 2010: Word email merge not selecting default Outlook account Using Outlook 1
M Outllook vba - selecting a folder Using Outlook 1
C Selecting days in business notes BCM (Business Contact Manager) 0
A Pull mail without marking and processing, only by selecting it Using Outlook 1
T Distribution Lists, Selecting members, filtering members out of the selection process (not one by one) Using Outlook 2
S E-mail contact Prompts when selecting TO: Using Outlook 2
T selecting and view multiple emails Using Outlook 2
G Selecting contacts from Groups within the Address Book Using Outlook 2
C Selecting calendar causes problems Using Outlook 2
J In Outlook 2010 selecting the Junk drop down for a message & then "Never block..." fails to add entr Using Outlook 7
S Unable to go to Inbox/Contacts Folder after selecting Public Folders. Using Outlook 1
C after selecting 'reply' font size is VERY small Using Outlook 2
S List Box - Selecting Multiple Items (Saving) Outlook VBA and Custom Forms 2
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 2
J Diane's Delay Delivery at Specific Times Questions Outlook VBA and Custom Forms 5
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
R Assign Categories "Round Robin" style but in a shared mailbox but on specific emails only Outlook VBA and Custom Forms 8
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 5
W Remove specific contacts from contact list Outlook VBA and Custom Forms 3
9 Outlook 2016 How to save an Outlook attachment to a specific folder then delete the email it came from? Using Outlook 1
S Outlook to check for specific text Outlook VBA and Custom Forms 3
RBLampert Assigning a newly (re)created e-mail account to a specific .pst data file Using Outlook 2
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
geofferyh Outlook 2010 How to Copy Outlook Attachment to a Specific Folder? Outlook VBA and Custom Forms 3
R Can not create folder to store specific emails in in Outlook for Mac Using Outlook 1
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
e_a_g_l_e_p_i Can you set reminder to specific times? Using Outlook 7
H Select Specific Account When Sending Email, Based on Current Folder Outlook VBA and Custom Forms 1
L Restrict accepted appts to specific calendar Using Outlook 2
P Import an .ics file to a specific calendar Using Outlook 4
D How to handle filing of emails from an Inbox Subfolder to a specific Public folder Using Outlook 1
J Save E-mail attachments in a specific folder Outlook VBA and Custom Forms 0
P Auto scroll to specific folder in Folder Pane Outlook VBA and Custom Forms 3
Similar threads


















































Top