Link to home
Start Free TrialLog in
Avatar of NVIT
NVITFlag for United States of America

asked on

How send appointment to certain Outlook calendar?

In the client's office, users all run Outlook.
No Exchange is used.
Each user's Outlook is stored in a .pst file.

In Outlook, one can have multiple calendars.

This client wants each user to have, in addition to the user's default Outlook calendar, a calendar dedicated to office events, i.e. an Office Calendar. Events / appointments in the office calendar should be separate from the user's default Outlook calendar.

In Outlook, you can create a new event/appointment. In that event, if you pick Invite Attendees, you can email it to various users.

Once the event is emailed, on the recipient's Outlook, when the calendar event is received, is there a way to send that event to the Office Calendar?

If so, can this be done via...
- Fancy vanilla Outlook setup?
- Or, via VBA programming?
- Or, via 3rd party programs?
ASKER CERTIFIED SOLUTION
Avatar of yo_bee
yo_bee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NVIT

ASKER

Hi YoBee.

Thanks for the code.

I haven't run it yet but I have some questions...

- I presume I put the code into ThisOutlookSession?
- Does the code run automatically? Or, do I have to assign it to a command icon?
- I think your code puts the received appt into folder: Backup Routine. Correct?
- Must folder Backup Routine exist? Or, is it created automatically?
- Must Subject String be exact? Or, can it be a prefix, e.g. FIRMWIDE - Category 1? Or, FIRMWIDE - Category 2
- I presume I put the code into ThisOutlookSession?
Yes: this is the easiest method
- I think your code puts the received appt into folder: Backup Routine. Correct?
How this works is when new appointment is added to the default calendar folder and the subject line contains "FIRMWIDE" it will be moved to another folder.  For my example I used "Backup Routine"
- Must folder Backup Routine exist? Or, is it created automatically?
No, This was just an example you can place it in any folder as long as the path is correctly entered in the code.
- Must Subject String be exact? Or, can it be a prefix, e.g. FIRMWIDE - Category 1? Or, FIRMWIDE - Category
No,  just contain it anywhere in the subject.  You can also use category field rather than the subject.

In regards to most of your questions the code will need some modification.  If you know the folder structure where this calendar will be placed, please supply it.  I will be happy to help.
Avatar of NVIT

ASKER

Thank you, YoBee...

I put this code into Outlook 2007.
I'd like to put into Outlook 2013 but don't' know how to get to the VBA code screen.

Outlook 2007 calendar has the option New Folder. But, I don't see that in Outlook 2013. I only see...
- New Calendar Group
- or, Add Calendar > Open shared calendar.

Forgive my ignorance but... I don't know what Calendar Groups and Shared Calendars are for. hehe.

Private WithEvents m_colCalendarItems As Outlook.Items
Private Sub Application_startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")


' default local Inbox
  'Set Items = objNS.GetDefaultFolder(olFolderCalendar).Items
    Set m_colCalendarItems = objNS.GetDefaultFolder(olFolderCalendar).Items

  
End Sub

Private Sub m_colCalendarItems_ItemAdd(ByVal Item As Object)
    Call UpdateReminder(Item)
End Sub

Sub UpdateReminder(Item As Object)

Dim ObjCalFolder As Outlook.MAPIFolder
'Rename the "Backup Routine" to the Calendar name in your mailbox.
Set ObjCalFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Backup Routine")

   If Item.Class = olAppointment Then
            'Change the Subject String to something that matches your environment.
        If InStr(1, Item.Subject, "RHA event") Then
             
           Item.Move ObjCalFolder
        End If
           
   End If
End Sub

Open in new window

You need to change the view to Folders rather than Calendar or Mail.
User generated imageUser generated image
To get to the VBA there are two ways.
  1. Press Alt + F11
  2. Enable Developer Ribbon:
  3. Click on File > Options > Customize Ribbon > Select Developer  
User generated image
Avatar of NVIT

ASKER

Thank you for the VBA tip.

> If you know the folder structure where this calendar will be placed, please supply it.

Below the default calendar, I'd like a folder named "RHA event"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NVIT

ASKER

Hi yo_bee...

I added your most recent change above.

I make an event with the subject prefix "RHA event" and invite (email) 1 user.

I don't think the code is running when I send the invite. I put a break point inside Sub UpdateReminder but it's not hitting it.

The event ends up in the default calendar.

I've tested sends from both Outlook 2007 and 2013.

Private WithEvents m_colCalendarItems As Outlook.Items
Private Sub Application_startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")


' default local Inbox
  'Set Items = objNS.GetDefaultFolder(olFolderCalendar).Items
    Set m_colCalendarItems = objNS.GetDefaultFolder(olFolderCalendar).Items

  
End Sub

Private Sub m_colCalendarItems_ItemAdd(ByVal Item As Object)
    Call UpdateReminder(Item)
End Sub

Sub UpdateReminder(Item As Object)

Dim ObjCalFolder As Outlook.MAPIFolder
'Rename the "Backup Routine" to the Calendar name in your mailbox.
'Set ObjCalFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Backup Routine")
 Set ObjCalFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Folders("RHA event")

   If Item.Class = olAppointment Then
            'Change the Subject String to something that matches your environment.
        If InStr(1, Item.Subject, "RHA event") Then
             
           Item.Move ObjCalFolder
        End If
           
   End If
End Sub

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NVIT

ASKER

> ...and press F5 or run the macro.  Each time you make a change you will need to do that.

Or, I presume, close Outlook. Then start it again.

I'll test this when I get in. Thanks, Yo_bee
That will do the trick as well
Avatar of NVIT

ASKER

Sorry. Just a minute. Let me confirm that error.
Avatar of NVIT

ASKER

Getting there...

Sending from Outlook 2007, it worked. Thanks again, yo_bee. If I make the event from the default calendar, I end up with just 1 event as expected placed in the correct calendar "RHA Event"

But, it seems to make a copy instead of moving it. Or, maybe when it is moved the name is prefixed with string "Copy"

User generated imageUser generated image
Avatar of NVIT

ASKER

My latest code... pretty much same as yours except added UCASE on line 30

Private WithEvents m_colCalendarItems As Outlook.Items
Private Sub Application_startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")


' default local Inbox
  'Set Items = objNS.GetDefaultFolder(olFolderCalendar).Items
    Set m_colCalendarItems = objNS.GetDefaultFolder(olFolderCalendar).Items

  
End Sub

Private Sub m_colCalendarItems_ItemAdd(ByVal Item As Object)
    Call UpdateReminder(Item)
End Sub

Sub UpdateReminder(Item As Object)

Dim ObjCalFolder As Outlook.MAPIFolder
'Rename the "Backup Routine" to the Calendar name in your mailbox.
'Set ObjCalFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Backup Routine")
 Set ObjCalFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Folders("RHA event")

   If Item.Class = olAppointment Then
            'Change the Subject String to something that matches your environment.
        If InStr(1, UCase(Item.Subject), "RHA EVENT") Then
             
           Item.Move ObjCalFolder
        End If
           
   End If
End Sub

Open in new window

Avatar of NVIT

ASKER

Another effect of the "Copy" issue...
If the originator cancels or Deletes the event, it doesn't send the update to the recipients as before.
I would have to do some testing on my end to see if I can replicate what you are seeing.
Give me a day or so.
Avatar of NVIT

ASKER

Thanks, yo_bee. That's much appreciated.
Avatar of NVIT

ASKER

Hi yo_bee. Just wondering if you had a chance to make progress on this.
If not, I'll just buy a 3rd party tool.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NVIT

ASKER

Thanks.
Avatar of NVIT

ASKER

Although it's not the ideal solution, I've given you the points.
thanks, but I would give some more insight what was beneficial.  I may help another use some of the information to help with their inquiry.