?
Solved

How to pass appointments from a Shared Calendar To personal Calendar in a Outlook Macro?

Posted on 2007-08-06
6
Medium Priority
?
469 Views
Last Modified: 2013-11-05
We want to be able to automatize the process of copy all the appointments in a shared Calendar to the personal calendar, since the only way to do this is selecting the appointments on the shared calendar and copy them to the personal calendar. we tried to use macros to do that but the macro recorder is not avaliable in outlook so we need to use a vbscript for the macro...
0
Comment
Question by:perifel
  • 4
  • 2
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 19642806
Hi, perifel.

That's doable, but it does present a problem.  Copying all the appontments from the shared to the personal calendar the first time is simple.  After that things become more difficult.  Unless the personal calendar is always going to be just an exact copy of the shared calendar, then you're faced with synchronizing the two calendars or with devising a way to erase the items from the shared calendar before the next run.  Synchronizing isn't a simple process.  It's possible, but it's complicated.  If you don't want to sync, then finding a way to delete the old appointments from the shared calendar is a must.  Othewise, you end up with duplicate appointments.  Deleting the appointments from the shared calendar is a lot easier than syncing, but it'll still require some planning.  If you want to go this route, non-syncing, then I can provide the code.  If you want to sync, then I'll be glad to offer suggestions, but that's too involved for me to produce the code.
0
 

Author Comment

by:perifel
ID: 19647562
Thanks for your coments!

It would be great if you can give us, both, the code for the non-sync  way, and the suggestions to the sync way, so we can work it out, and find the solution that fits the best for us.

Thanks in advance.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1500 total points
ID: 19674659
Sorry to be slow getting back to you.  The code for the non-sync solution is below.  I haven't tested it, but it should work.  It works by deleting all of the shared calendar appointments from the private calendar and then copy the shared appointments to the private calendar.  The delete process depends on the categories field of each shared calendar entry containing the word "SharedCalendar".  If you don't want to enter that word as you create each entry, then we could modify the code to insert it for you as it copies each item.

Sub CopyAppointmentsFromFolder()
    Dim olkSource As Outlook.MAPIFolder, _
        olkDest As Outlook.MAPIFolder, _
        olkAppt As Outlook.AppointmentItem, _
        olkCopy As Outlook.AppointmentItem, _
        intIndex As Integer
    'Change the folder path on the following line to that of the shared calendar
    Set olkSource = OpenOutlookFolder("Path")
    'Change the folder path on the following line to that of the private calendar
    Set olkDest = OpenOutlookFolder("Path")
    'Delete the shared calendar appointments from the private calendar
    For intIndex = olkDest.Items.Count To 1 Step -1
        Set olkAppt = olkDest.Items.Item(intIndex)
        If InStr(1, olkAppt.Categories, "SharedCalendar") Then
            olkAppt.Delete
        End If
    Next
    'Copy the shared calendar items to the private calendar
    For Each olkAppt In olkSource.Items
        Set olkCopy = olkAppt.Copy
        olkCopy.Move olkDest
    Next
    Set olkCopy = Nothing
    Set olkAppt = Nothing
    Set olkDest = Nothing
    Set olkSource = Nothing
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 1500 total points
ID: 19674713
The syncing solution depends on a key field you can use to match items.  The problem is that Outlook has no such field.  Yes, each item in Outlook does have a unique identifier called EntryID.  The problem is that the value of EntryID is based on the container the item is in.  Thus, item X will have an EntryID of Y in one container while an exact copy of X will have an EntryID of Z in a different container.  That makes EntryID unusable for matching items in a sync routine.  The Subject field won't work since it's possible to have any number of items with the same Subject.  Date/time fields won't work, since item X and a copy of Item X will always have different dates/times since one has to have been written after the other.  So, we have to create a field to match and sync items and figure a way to assign unique values to that field from either container.  Creating the field is no problem.  Filling it in is the problem.  The best solution would be to use a web service so you get the IDs from a single source.  That may not be possible though if you have notebooks that might be used while disconnected from the network and therefore unable to access the web service.  Another possibility is to assign a computer specific prefix to the ID.  All records from computer XYZ would have a unique ID begining with XYZ.

The second issue is how to handle deletions.  Adds and updates are no problem since in both cases the item is there.  For an Add there'll be a record in one container and not the other.  We simply need to copy the record to the other container.  For an Update the same record will exist in both containers, but will be newer in one than the other.  We overwrite the older record with the newer one.  Deletes pose a problem since they look like an Add, a record exists in one container but not the other.  But, we don't want to copy the record to the container it's missing from, we want to delete it.  So, how can we tell when there's been a delete?  One way is to mark records for deletion rather than actually deleting them immediately.  Outlook doesn't support that natively though.  Another way would be to move records we want to delete to a separate folder and have the sync routine process records in it as a deletion.  However, that requires teaching everyone to delete properly.  Better to have a means that doesn't require special actions by the user.  The only way I can think of to solve this is to write a journal of actions.  We'd need to write code that traps delete events and writes a transaction journal.  The sync routine then reads the journal as part of its process.

A third issue is how to handle changes to the same record in both containers.  User A changes the phone number of record X in one container while user B changes the address of record X in the other container.  When the sync runs oen fo those changes will be lost because we only know that the record changed, not what was changed in it.  The last change made will overwrite the earlier change.  If the address change was entered last, then the phone number change will get lost altogether.  The journaling idea will solve this too.  When a record is changed the journaling action will record what was changed in the record.  That way both the address and phone number changes will be preserved.  Journaling isn't built into Outlook, so this will require writing your own from scratch.  It'll require trapping add, change, and delete events, recording what was changed on a per field basis, and writing that information to a file that the sync routine can use later.  It's doable, but it'll require an investment in time and effort to get it working.  
0
 

Author Comment

by:perifel
ID: 19710540
Thanks!

We´ve already made a couple of scripts that solve th problem in a non sync way. the main diference with the code you gave us, is that we "peek" into the shared calendar and only copy the appointments that are necesary, also we use some restrictions in the script so it have a better performance, (In calendar with many appointments the response time was too long)

Thanks for your help an if someone wants the code we made, contact us ;).
0
 
LVL 76

Expert Comment

by:David Lee
ID: 19712436
You're welcome.  Glad I was able to help out.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question