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.
select_all_icon.jpg
page_white_copy.png

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
 
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)
 
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.
 
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
 
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
 
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.
Similar threads
Thread starter Title Forum Replies Date
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
K Selecting a folder from an entry in a Listbox Outlook VBA and Custom Forms 1
N Selecting multiple calendar items Using Outlook 4
M 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
S List Box - Selecting Multiple Items (Saving) Outlook VBA and Custom Forms 2
N Reply to Outlook messages by moving messages to a specific Outlook folder Outlook VBA and Custom Forms 1
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
K Add an entry to a specific calendar Using Outlook 1
G Adding a contact to a specific folder Using Outlook 0
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
W OL giving basic auth when logged in to Win as specific user Using Outlook 0
D Outlook 365 Forward Meeting Related Messages to Specific Meeting Organizer Outlook VBA and Custom Forms 0
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
Z Copy specific email body text Outlook VBA and Custom Forms 0
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
J Autoreply email recieved from specific sender after deleting some text from body. Using Outlook 0
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 4
J Diane's Delay Delivery at Specific Times Questions Outlook VBA and Custom Forms 7
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 6
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

Similar threads

Back
Top