• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

Macro in Outlook 2013

Hi

Approximately 3 years ago, a brilliant expert BlueDevilFan helped me with a Macro I needed for Outlook which worked with Outlook 2007 and Outlook 2010 althought it was originally written by him for Outlook 2007.

So here is the background of what it does right now.

A user has Outlook profile configured normally but has a few subfolders under the main calendar folder and these subfolders are also calender folders.

Now, the main calendar and the subfolders all contain appointments and many of them are recurring appointment. Many of the appointments are only for a few occurrences for example 5 or 10 or 20 etc.

When you normally do a search for any appointment in Outlook, if it matches a recurring appointment, it will only be shown as one result in the search result with the little circle with arrows over it suggesting it is a recurring appointment.

However, for the same recurring appointment, the user actually want to see individual occurrences of the appointment so that they can open any particular one directly from the search result.

So the macro is used this way. Once the search result shows the recurring appointment entry, you highlight on it and run the macro. The Macro will bring up a box showing the various occurrences of the appointment that was selected and from within that box, you can select any particular occurrence and double click on it to open just that one particular occurrence of the appointment.

I have attached the files I was given which I simply had to import in Outlook.

The problem I have is that the code is not working in Outlook 2013 and I need it working in Outlook 2013.

Ask me any questions you have about this as I know this is quite complex.
ShowRecurring.zip
0
alex110109
Asked:
alex110109
  • 9
  • 6
1 Solution
 
alex110109Author Commented:
Also, here is the link to the question from 3 years ago.

http://www.experts-exchange.com/Software/Internet_Email/Email/Email_Clients/Q_26229789.html

I am sorry its a long one but you know how things go when you are doing things like this.

I hope genius Mr BlueDevilFan himself can help me again !!
0
 
David LeeCommented:
Hi, alex110109.

I tried the solution and got the same error.  I traced it to the ShowRecurring subroutine.  It looks like two lines of code have typos.  Those two lines are

    strSubject = Application.ActiveExplorer.Selection(1)

and
   
    strSubject = Application.ActiveInspector.CurrentItem

They should read

    strSubject = Application.ActiveExplorer.Selection(1).Subject

and

    strSubject = Application.ActiveInspector.CurrentItem.Subject

I looked back at the original question and see that they're wrong there too.  I'll see what I can do about fixing them for anyone else who reads this question.

Once I corrected them, then code worked fine.
0
 
alex110109Author Commented:
Hi Blue

I will try this and get back to you asap.

I am out of the office today so I will check it tomorrow morning.

Thanks again for your help.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
David LeeCommented:
No worries.  You're welcome!
0
 
alex110109Author Commented:
Hi Blue

I think we are almost there but in the test I did, its still coming up with an error.

We have certainly made progress compared to how it was before.

So I have attached a zip file with screenshots which are named in order.

If you follow the files in that order, you see what happens.

Is there unnecessary code in the frmShowRecurring form?

The first three or four lines I mean?
0
 
alex110109Author Commented:
oops...as usual, forgot the attachment.
macro.zip
0
 
David LeeCommented:
How did that one line of code end up outside of a subroutine?  Delete it and try running the macro again.
0
 
alex110109Author Commented:
Hi Blue

Thanks for that.

I did it and still got an error which I think is different from the other one.

May be I didn't delete the right entry.

See the error message and the code.
macro7.png
0
 
alex110109Author Commented:
Or, may be you can export the code from your end as it is working fine for you?

Whichever way is easier for you.
0
 
David LeeCommented:
You need to delete the line that has the highlight on it.  The one after the End Sub line.
0
 
alex110109Author Commented:
Hi Blue

Sorry to be a pain but now there is a dialogue box with just the word "error" in the title and nothing in the box itself. You can see it in the attached screenshot.

I have also attached a text file containing the current code, in case I have deleted the wrong line compared to the code you have working on your end.

The code is for "frmShowRecurring" form.

Interestingly though, this time when you click on Ok to the error message, it doesn't open the Visual Basic editor like it used to do with errors before.
macro8.png
code.txt
0
 
David LeeCommented:
No worries.

Here's the code as I have it.  It's working for me.

Dim strSubject As String

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOpen_Click()
    Dim olkCal As Outlook.Items, _
        olkApt As Outlook.AppointmentItem, _
        olkFld As Outlook.MAPIFolder, _
        arrTemp As Variant, _
        datSelected As Date
    arrTemp = Split(Me.lstInstances.List(Me.lstInstances.ListIndex), vbTab)
    datSelected = arrTemp(1)
    Set olkFld = Application.ActiveExplorer.CurrentFolder
    Set olkCal = olkFld.Items
    olkCal.Sort "Start"
    olkCal.IncludeRecurrences = True
    Set olkApt = olkCal.Find("[Subject] = '" & strSubject & "' AND [Start] = '" & Format(datSelected, "ddddd h:nn AMPM") & "'")
    If TypeName(olkApt) = "Nothing" Then
        MsgBox "Error"
    Else
        Me.Hide
        olkApt.Display
    End If
    Set olkCal = Nothing
    Set olkApt = Nothing
    Set olkFld = Nothing
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    ShowRecurring
End Sub

Sub ShowRecurring()
    Dim olkCal As Outlook.Items, _
        olkApt As Outlook.AppointmentItem, _
        olkFld As Outlook.MAPIFolder, _
        intCounter As Integer
    intCounter = 1
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            strSubject = Application.ActiveExplorer.Selection(1).Subject
        Case "Inspector"
            strSubject = Application.ActiveInspector.CurrentItem.Subject
    End Select
    Set olkFld = Application.ActiveExplorer.CurrentFolder
    Set olkCal = olkFld.Items.Restrict("[Subject] = '" & strSubject & "'")
    olkCal.Sort "Start"
    olkCal.IncludeRecurrences = True
    For Each olkApt In olkCal
        Me.lstInstances.AddItem intCounter & vbTab & olkApt.Start
        intCounter = intCounter + 1
        If intCounter > 50 Then Exit For
    Next
    Set olkFld = Nothing
    Set olkCal = Nothing
    Set olkApt = Nothing
End Sub

Open in new window

0
 
alex110109Author Commented:
Mr BlueDevilFan

You are a star as always.

Got it working although on some appointments it still comes up with the same error.

But that doesn't matter because we only need to see the list of occurrences and if a particular occurrence opens up, that's a bonus !!

Can't thank you enough !!
0
 
alex110109Author Commented:
Excellent help provided !!
0
 
David LeeCommented:
Thanks, alex110109, and you're welcome.  I'm glad I was able to help.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now