Link to home
Start Free TrialLog in
Avatar of Alex T
Alex TFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Viewing Recurring appointments in Outlook

Hi Experts

We have a customer who uses recurring appointments heavily for booking their engineers out.

Basically they have their own clients where they regularly send out engineers to.

So for a typical customer, they will book an engineer to visit on every 3 weeks for up to 14 visits.

So setting the appointment recurrence is not a probelm at all. The problem is searching.

If their customer call them and say that when is the 7th appointment because they need to change it, the user has to search for it. The search will unfortunately find only one appointment with recurrence but it will not show the actual dates when that recurring appointment occurs.

So the question is, is there a way to see the occurrances of a recurring appointment?

One can always count manually, but that is hardly the point of using technology !!

It it is possible to view the recurring appointments in a calender view, thats great but a search result with list view would also be fine as you can quickly scroll down to, say the 7th line, for finding out the 7th occurrrance.

Please ask me any questions just in case I have not been clear here.

Alex
Avatar of David Lee
David Lee
Flag of United States of America image

Hi, alex110109.

I don't know if this is what you're looking for or not.  It builds a list of the recurrences of a given appointment and displays them in IE.  You can click on an occurrence to open the actual item.  The items are numbered to make it easy to find the occurrence you're looking for.  It works fine in Outlook 2007.  I don't have 2010 loaded yet, so not sure about it.

Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

Outlook 2007 doesn't automatically install the URL protocol handler for Outlook items.  You have to edit the registry and add an entry.  Here's a link to a page with details: http://mutable.net/blog/archive/2006/09/02/how_to_hyperlink_to_microsoft_outlook_messages.aspx.  I don't know if 2010 adds the protocol handler or not.

To use the code

1.  Run the macro
2.  Enter the name of the appointment to find
3.  IE will open and display a list of up to 50 recurrences of the appointment
4.  Click an occurrence to open the Outlook appointment



Sub ShowRecurring()
    Dim olkCal As Outlook.Items, _
        olkApt As Outlook.AppointmentItem, _
        intCounter As Integer, _
        strSubject As String, _
        strResults As String, _
        objIE As Object
    intCounter = 1
    strSubject = InputBox("Enter the title of the appointment to find.", "Show Recurring")
    Set olkCal = Session.GetDefaultFolder(olFolderCalendar).Items.Restrict("[Subject] = '" & strSubject & "'")
    olkCal.Sort "Start"
    olkCal.IncludeRecurrences = True
    For Each olkApt In olkCal
        strResults = strResults & "<tr><td align=""right"">" & intCounter & "</td><td><a href=""outlook:" & olkApt.entryID & """>" & olkApt.Start & "</a></td></tr>"
        intCounter = intCounter + 1
        If intCounter > 50 Then Exit For
    Next
    strResults = "<table>" & strResults & "</table>"
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "about:blank"
    Do While objIE.readyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    objIE.Document.Body.innerHTML = strResults
    objIE.Visible = True
    Set olkCal = Nothing
    Set olkApt = Nothing
End Sub

Open in new window

Avatar of Alex T

ASKER

Hi Blue
This is great work from you but the problem is, we can't expect the user to open the code and put the name of the appointment in it to look for occurranes of a particular appointment.
Besides, they have so many appointments that they will need to first search for the appointment in the first place using a keyword.
So is there a simpler solution you can come up with?
"we can't expect the user to open the code and put the name of the appointment in it to look for occurranes of a particular appointment. "

Nor do they have to.  The code prompts for the appointment to find.  Did you try running it?

---

"So is there a simpler solution you can come up with?"
I can modify the code to use the selected appointment instead of having to enter a name.  Would that be better?
Avatar of Alex T

ASKER

Yes that would be better. However the best thing to do is if your code can accept a keyword. Because as I said they will first search the calender to find that particular appointment and then look for a particular occurrance of it.

This is because they literally have hundreds of appointments.

I think they wouldn't mind using a different interface for this task, as long as it works fine.
What do you mean by keyword?  It already accepts a subject.
Avatar of Alex T

ASKER

I mean to say...if i have the following line in subject for example
"Alex at Tesco Bakery , London SE1 0AA, every thursday"
Will I have to put the whole line as input or can i just put in for example, Tesco or SE1 0AA?
The customer will first look for this appointment by searching for the keyword for example Tesco. So they find this appointment which is a recurring appointment. So once they find it, then they want to see a particular occurance of the appointment.
So I hope you understand what the situation is.
Got it.  Rather than write code to perform the keyword search, present the results, allow the user to make a selection, then pull up all the instances of that appointment, it'd be more efficient to use Outlook's built-in search capability to find the appointment and then use code to pull up all the instances of that appointment.  Do you agree?
Avatar of Alex T

ASKER

Hi Blue
I understand that.
However, how do I run this code on an appointment that the user finds after search.
Let me know.
 
I'd recommend what I proposed earlier, selecting an appointment and then running the code.  A sequence of events something like this

1.  The user opens the calendar
2.  The user uses Outlook's built in search to locate an appointment series
3.  The user selects (i.e. clicks on) an appointment in the series
4.  The user runs the macro
5.  The macro finds all occurrences of the selected appointment and displays them in the browser

Would that work?
Avatar of Alex T

ASKER

Hi Blue
I think that can definately work.
So I guess you need to modify the code as the current code seem to need the subject of the appointment listed within the code itself.
One more thing. Which might be very important.
These guys just bought Office 2007 so they will be going to Office 2010 soon. Do you think this will also work with Office 2010?
 
Avatar of Alex T

ASKER

Hi Blue
Can you get back to me as soon as you can? I need this resolved like yesterday. If you can't do it, its not a problem, its just that I can start looking elsewhere.
I believe you are very close to fixing the issue and just need to modify the code u have written to make it work.
So if you can get back as soon as possible, that will be great!!!
Sorry to be slow.  I've modified the code below to perform as described  in post 32913281.
Sub ShowRecurring()
    Dim olkCal As Outlook.Items, _
        olkApt As Outlook.AppointmentItem, _
        intCounter As Integer, _
        strSubject As String, _
        strResults As String, _
        objIE As Object
    intCounter = 1
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            strSubject = Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            strSubject = Application.ActiveInspector.CurrentItem
    End Select
    Set olkCal = Session.GetDefaultFolder(olFolderCalendar).Items.Restrict("[Subject] = '" & strSubject & "'")
    olkCal.Sort "Start"
    olkCal.IncludeRecurrences = True
    For Each olkApt In olkCal
        strResults = strResults & "<tr><td align=""right"">" & intCounter & "</td><td><a href=""outlook:" & olkApt.entryID & """>" & olkApt.Start & "</a></td></tr>"
        intCounter = intCounter + 1
        If intCounter > 50 Then Exit For
    Next
    strResults = "<table>" & strResults & "</table>"
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "about:blank"
    Do While objIE.readyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    objIE.Document.Body.innerHTML = strResults
    objIE.Visible = True
    Set olkCal = Nothing
    Set olkApt = Nothing
End Sub

Open in new window

Avatar of Alex T

ASKER

Hi Blue
Thanks for the code but I am struggling with the URL handler from the other article. Can you do a .reg file for me for that?
Without it, when I run the macro, it doesn't do anything.
Avatar of Alex T

ASKER

Hello Bleu
I am trying to run this code but I need to do the registry setting as per your earlier post.
I can't find HKCR\Outlook key at all.
Can you help me with that? Without this, I can't move forward.
I would appriciate if you get back to me as soon as possible.
Thanks.
Sorry to be slow, I'm on a business trip and my time for working on EE questions is limited.  

Are you saying that when you open regedit you don't see 5 hives, the first of which is HKEY_CLASSES_ROOT?
Avatar of Alex T

ASKER

Hi Blue
The article refers to HKCR\Outlook but I can't find Outlook under HKCR. I looked for it on a XP Pro with Office 2007, Vista with Office 2007 as well as Windows 7 with Office 2007.
Can you help me locate it? I am available on IM if that helps speed up the troubleshooting.
HKCR is an abbreviation for HKEY_CLASSES_ROOT.  Are you saying that HKEY_CLASSES_ROOT doesn't appear when you open Regedit?
Avatar of Alex T

ASKER

Hi Blue
I am aware that HKCR is Hkey_Classes_Root
I am saying I can't find HKCR\Outlook.
I am not saying I can't find HKCR itself. HKCR is there ofcourse.
Got it.  Of course it doesn't exist.  You have to create it.  That's the point of the article.  Just create those keys and values as described in that article.  I exported that key to a reg file to make it easier.
Outlook-2007-Protocol-Handler.reg
Avatar of Alex T

ASKER

Oh I c....proper Homer Simpson moment there....Doh.
Thanks for the reg file...will just use that.
Let see...now.
Avatar of Alex T

ASKER

Hi Blue
Ok so I added the reg file and created the macro with the code you provided.
I first search for an appointment that is a recurring appointment with a keyword search in the calendar.
When I find a few results, I highlight the one I need and then run the Macro.
The outlook freezes fr a while and then comes back to life but nothing else happens.
Is it possible for you to test it your end?
I can setup a demo account if you want...it is a standard exhcange and outlook setup.
I just tested and it works perfectly here.  Here are the steps I followed:

1.  Open the calendar
2.  Select a recurring appointment (I had one visible on the screen, didn't need to search)
3.  Run the macro
4.  IE opened with a list of all the iterations of that appointment
Avatar of Alex T

ASKER

Hi Blue
What can I be doing wrong here?
How can we move forward?
I can give you remote access into a virtual machine we have and then we can have an online chat simultaneously if you think this will help fix the issue quickly.
I am really greatful to you for this and would be happy to award 1000 points if it was possible.
I just need this working.
Avatar of Alex T

ASKER

Also, if this helps, running the macro asks me for the name of the appointment.
I was under impression that you changed the code so it takes the subject of the highlighted appointment as input automatically and finds all ocurranecs of that appointment.
I did change it.  You must have the older code in place.  There are no prompts in the version I posted in comment 32937423.
Avatar of Alex T

ASKER

Hi Blue
I have done the macro again with the correct code and it is still doing the same.
Please Help!!
I have attached the images...go through them in order as I have named.
The appointment that I am trying to use is the one which is "To Do".
 

1.jpg
Avatar of Alex T

ASKER

here are the screenshots in a zip file. I thought I was able to attach more than one file at one time.
See the last screenshot...you can see the Outlook has frozen and nothing happens after that.
Please let me know if you need anymore information
I must say now I am not being promted to enter the subject of the appt so I must have had the old code.
But the new code is not bringin up the page in IE. Can you, just for me viewing pleasure, send me a screenshot of the IE page so I can atleast see what it will look like?
Let me know how we should proceed.

screenshots.zip
Here's a screen shot of what you should see.  

On line 26 change READYSTATE_COMPLETE to 4.  Try running the code again.

ShowRecurring.jpg
Avatar of Alex T

ASKER

Hi Blue
This is excellent. I will try it again and let you know.
Avatar of Alex T

ASKER

Hi Blue
 
So should the line 26 look like this?
Do While objIE.readyState <> READYSTATE_COMPLETE 4
Or am I supposed to completely replace it with 4? like this?
Do While objIE.readyState <> 4
 
Let me know.
Completely replace it so that line looks like this

Do While objIE.readyState <> 4
Avatar of Alex T

ASKER

Hi Blue
This is great stuff....its working on my end and is almost perfact solution for me. Needless to say you have already earned the points and I would award more if I could. Just need to test it in production environment now.
That's great.  Thanks, I appreciate the thought.
Avatar of Alex T

ASKER

Hi Blue
Ok so this works fine on a user's personal calender and again, I can't emphesize how crucial this is for us.
Our situation is a bit more complicated and may need the code to be tweaked for what we need to do. We have calender sub folders and shared calenders involved for which this macro doesn't work.
Should we carry on here or should I start a new question?
Its an extension of this question but technically can be a new question.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
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 Alex T

ASKER

Hi Blue
That's great, I will try this and get back to you.
 
Avatar of Alex T

ASKER

HI Blue
Ok, that works so that is even better.
But can I be satisfied? No...I want more....
The resulting webpage lists all the ocurrances which is what I wanted.
However, the hyperlink to for any entry actually opens up the series and not that particular ocurrance.
I don't even know if this is possible, if it is something that is a quick change in the code, great. but if not...I know I am trying my luck here.
I think i already have what I was looking for so if this can't be done or requires a lot of work, we can definately stop here.
For the first time, I am itching to award points :)
Sorry to be slow.  There doesn't seem to be a way to get that (i.e. linking to a particular instance) to work using the approach I took (i.e. showing the links in an Internet Explorer window).  To get around that problem I had to create a userform.  Follow these instructions to use this solution.

1.  Save the attached file to your heard drive and unzip the two files it contains.
2.  Rename both files by removing .txt from each file's name.
3.  Open Outlook
4.  Click Tools > Macro > Visual Basic Editor
5.  Click Files > Import File
6.  Navigate to the folder containing the two unzipped files
7.  Select the file frmShowRecurring.frm
8.  When the import is complete expand Forms.  You should see a form there named frmShowRecurring.
9.  Add the code below to Outlook.

When you want to find an instance of a recurring appointment

1.  Open the calendar
2.  Find a recurring appointment
3.  Select the appointment on the calendar
4.  Run the macro FindRecurring
5.  Select the instance of the appointment you want to edit
6.  Click the Open button.
Sub FindRecurring()
    Dim frmRecurring As frmShowRecurring
    Set frmRecurring = New frmShowRecurring
    frmRecurring.Show
    Set frmRecurring = Nothing
End Sub

Open in new window

ShowRecurring.zip
Avatar of Alex T

ASKER

Hi Blue
I followed you instructions till importing the file.
But where do I add the small code in your last post?
I have the hirarchy as below.
 
==============================
Project1 (VbaProject.OTM)
          Microsift Outlook Objects
                    ThisOutlookSession  (This is where I paste the main code)
          Forms
                     frmShowRecurring
================================
 
So the only place I can see I can type the small code in your last post is where I have the main code.
Please let me know.
Also...may be I didn't test this properly before but now...when I run the original macro on some of the recurring appointments, the IE window opens up, but there are no occurrances listed. The IE windows is totally blank. What could be the issue here?
 
 
Avatar of Alex T

ASKER

Hi Blue
Ok, my further investigation found this...
 
1. If there is a recurring appointment which started and finished in the past, your macro will not find any ocurrances.
2. Similarly, if there is a recurring appointment which starts in future and (obviously) ends in future, again, your macro will not bring up any ocurrances.
In both scenarios, the IE window is just blank.
Only if a recurring appointment started in the past and either ends today or some other day in future, your Macro brings up the ocurrances listed in IE.
Is it easy to fix?
Add a module under Modules and place the code in it.
Avatar of Alex T

ASKER

Hi Blue
I will try this and get back to you.
However, did you go through my comments about the main code?
It doesn't seem to work for any appointments that start and finish in past or future.
Is this something easy to fix?
I did see that, but I'd like to focus on the new code and you mentioned it in the context of the old code.  Once you get the new code in place if that's still a problem, then I'll address it then.
Avatar of Alex T

ASKER

Hi Blue
That's fine, I will try out the new code and let you know.
 
Avatar of Alex T

ASKER

Hi Blue
Again, you have done it.
The new code works like a charm.. the only niggle is that it takes some time before it opens the ocurrance once you click on the button "Open". But that may be because I am trying it in a virtual machine so I will try it on production environment now and get back to you....but you my friend, are a genius...
Thanks!  Please let me know if there's anything else I can do to help out.
Avatar of Alex T

ASKER

Hi Blue
I am sorry to keep pestering you...but this one is interesting.
So we have 5 sub calanders on one of the computers...which is the primary user.
There is a secondary user who accesses those 5 calenders as shared calenders.
I tested the macro on both these users and it works on the secondary user's Outlook but it doesn't work on the primary user.
This is interesting considering, if anything, it may have issues working on a sub calander which is also a shared calender as opposed to just asimple sub calender.
On the primary user's computer, it comes up with just empty box. Any clue at all?
I'm not sure I understand.  Are you saying that the solution works fine for someone who is accessing these 5 calendars as shared calendars but does not work for the owner who is signed into the mailbox?  
Avatar of Alex T

ASKER

Hi Blue
Yes, that's correct. For the owner of the mailbox who has those 5 calanders as sub folders, it doesn't work for any appointment. It just brings up a blank box. Is it possible that I pasted the code incorrectly?
How do I reset Outlook so that it doesn't have any macros so I can try again?
I did delete the macro 3 times and tried again but didn't help, but that was like deleting it manually as opposed to resetting it may be.
 
I think it's pretty unlikely that incorrectly pasted code is the cause, but I can't rule it out.  Outlook does not have a reset button for macros.  Other than manually deleting code the only way I know of to "reset" is to delete the file that stores the code.  If you want to do that, then here's how.

1.  Close Outlook
2.  Find the file VbaProject.OTM.  It'll be in the c:\Users\<user>\AppData\Roaming\Microsoft\Outlook\ folder on a computer running Vista.  On an XP computer it'll be in the folder c:\Documents and Setting\<user>\Application Data\Microsoft\Outlook.  Explorer will have to be set to view hidden files and folders for you to find the target folder.
3.  Delete the file
4.  Restart Outlook

Outlook will automatically create a new code file.  Keep in mind that this one file stores all Outlook code.  Deleting it will delete all Outlook macro code on that computer, not just this code.
Avatar of Alex T

ASKER

Hey Blue
I will try this and get back to you.
Thanks
Avatar of Alex T

ASKER

Hi Blue

I don't know what's going on but something is strange.

I feel like we are designing a software :)

So deleteing the OTM file didn't help. So we created a brand new user profile and then it worked fine.

However, when we wanted to show it to the user, while running the macro, it came up with a message saying "the macros are disabled in this project, refer to documentation" to enable it.

I did some googling and found that I need to sign the macro using the VBA tool and then assign the certificate to the macro. This worked and now I could run the macro.
 
But now this is what happens. If I go to a calander and select an appointment and run the macro, it runs as expected. Remember this is when it is in the day view, which is the default view.

But when we do the search for an appointment, it obviously comes up with the result in the catagory view which is kind a list. Then I select one of the appointment and run the macro to see occurrences of that appointment. The macro runs and fine and brings up the box but it doesn't show the occurrence. The box is empty...

So I don't know what's wrong.

Can you think of something?
Sorry, I'm confused.  Please give me the exact steps you used and I'll see if I can duplicate the issue.
Avatar of Alex T

ASKER

Sure
So here is the problem
For the user who has the original calenders, the macro is not working.
It runs but only show empty box.
You suggested to delete the VBProject.OTM file from under the Appdata folder within the user's profile, as per post no:  33237209.
Following the post no:  33237209 didn't work for me. So I deleted the whole user profile.
Created a brand new user profile, configured the Outlook. Since it is a Microsoft Exchange mailbox, all the data is on the server so we don't need to worry about it.
So brand new user profile with Outlook configuration from scratch and brand new macro worked for me when I tested it.
So I was happy and agreed to demo it to the user saying "ok I have got it working now".
But when I went to show it to the user, the macro didn't work. When I ran the macro it came up with a message saying "Macros are disabled in this project, refer to documentation" to enable them.
So I did some google search and found a solution to that problem, I needed to sign the macro using the VB tools or something which I did and at least it fixed that problem where it didn't come up with that error message again.
But now the behavior of the macro changed.
When I go to calander and select an appointment in the normal view, run the macro, it works fine.
However, if I do a search, the search result comes in the list view. Here if I select an appointment and run the macro, it brings up the box as it shoud, but it doesn't show any ocurrances of the appointment , it just shows empty box.
I am not sure if u will be able to duplicate it your end as I can't duplicate it on my laptop.
I can't duplicate it on the same computer under a different user profile as well.
So may be I will delete the profile again and let you know. But if you know something as to in what situation the macro would show empty box, let me know.
Line 16

    Set olkFld = Application.ActiveExplorer.CurrentFolder

is the most likely cause.  It's getting the currently selected folder.  My guess is that the currently selected folder isn't the calendar or is a different calendar.  What I can't understand is how it could work in all of your test scenarios except for one.
Avatar of Alex T

ASKER

Hi Blue
I will try this and get back to you.
Yes it is very strange.
Also the fact that it actually worked fine for the user herself but only when we wanted to show her, it came up with a problem.
Avatar of Alex T

ASKER

Hi Blue
You are saying line 16?
Where is line 16, the code is of only 6 lines or something.
I tried again and came up with exact same behavior.
First the message comes up about macros being disabled in the project and after that, the macro doesn't run properly on search results i.e. bringin up empty box, but runs fine if run on an individual appointment in any calander.
Please let me know where you intended by line 16?
The six lines of code call the form.  The form had about 60 lines of code behind it.  With all the changes I did get confused though.  It's line 48 in the form.
Avatar of Alex T

ASKER

Hi Blue
Please confirm
Do I need to add at line 48 or replace line 48?
Currently line 48 is
Private Sub UserForm_Initialize()
If I am to add your new line at line 48, we will have below
Line 48: Set olkFld = Application.ActiveExplorer.CurrentFolder
Line 49: Private Sub UserForm_Initialize()
I know we have been making a lot of changes and it can get confusing very quickly.
I will try both ways but if you can confirm in the mean time, that will be great.

No, don't change anything.  Yes this

    Set olkFld = Application.ActiveExplorer.CurrentFolder

is line 48.  I was just making a comment that the only rationale I could think of for the search not returning anything is if the wrong folder was selected.
Avatar of Alex T

ASKER

Hi Blue
Just to clerify, I am not too sure, whether a particular folder is in focus or not when we do the search.
Also when we do the search, the search results are from all folders and not just from one particular calender folder.
I will try this and get back to you.
Avatar of Alex T

ASKER

Hi Blue
I tried this and hasn't made any difference.
Avatar of Alex T

ASKER

Hi
Sorry, didn't mean to post a short reply, pressed the mouse by mistake :)
So that line 48 thing didn't work.
What I think is happening is this.
When we do the search and get the search result, it gives you a list of appointments which can be from any folder.
I get the feeling that the code is failing to run against the selected appointment. Its like running the code against a patch of time that doesn't have any appointments. That's why it is bringing up empty box.
 
"When we do the search and get the search result, it gives you a list of appointments which can be from any folder."
Then this is the problem.  The code can only handle a search in the current folder, bot a global search of all folders.
Avatar of Alex T

ASKER

hmm.....I think so we have reached the end here and now we are looking at doing what is impossible by design I guess.
i guess the key is understanding where does the search result are stored from a folder point of view.
I don't want to push you further onthis Blue, I have already got more than what I asked for.
Should we close the question here?
I think that's a good idea.

I just need to clarify one point.  The script can only run against a given folder.  I understood the sequence of events to be that the user would go to a calendar (a given folder), search for a particular appointment, select it, and then run the macro to retrieve all occurrences.  All instances of a given appointment must occur in the same folder since there is no way in Outlook to have them occur in different calendars.  If instead the user is using advanced search to search the entire mailbox, then the script can't work properly because the resulting list of matches aren't in a given folder.
Avatar of Alex T

ASKER

Hi Blue
I understand that and I am really grateful to you for doing this.
I am not sure if I mentioned this but even Microsoft has confirmed they don't have this functionality on Outlook. I had spokent o MS Support team.
So what we have achieved here is something beyond even Microsoft I would say.
You deserve 10,000 points for this.
Thanks
You're welcome.  Glad I could help out.