• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Move Appointments to an Archive Calendar

Slipstick Systems

› Developer › Move Appointments to an Archive Calendar

Last reviewed on September 19, 2018     17 Comments

This code removes the reminder and categories and moves the appointment to a calendar in an archive folder or a subfolder under the calendar.

I want to be able to do 3 things with just one click of a button:
With a Calendar event selected, I want to:
1) Erase any Reminder (set Reminder to: 'None'),
2) Clear All Categories,
3) Move the event to another calendar (in My Calendars) named "DONE" (where I keep finished-completed things).
Since this is something I do everyday, multiple times a day, I want to save time by having a macro do all those things with one click.

Removing the reminder and clearing categories is as simple as changing the field values. Moving the event is also a simple process , although it requires a function that gets the filepath if the calendar you are moving the event to is not in the default data file.

The code Set CalFolder = GetFolderPath("Archive\Done") moves the appointment to a calendar folder called "Done" in the Archive pst.

Use Set CalFolder = Session.GetDefaultFolder(olFolderCalendar).Folders("Done") to move the appointments to a subfolder of the calendar. Note: if you are moving the item to a subfolder of the data file, you don't need to use the GetFolderPath function.

For more information on folders and data files, see Working with VBA and non-default Outlook Folders.

The GetCurrentItem function detects whether the appointment is selected or opened. For more information, see Outlook VBA: work with open item or selected item.

Public Sub MoveCalendar()

Dim objAppt As Outlook.AppointmentItem
Set objAppt = GetCurrentItem()

' move to a calendar in an archive data file
Set CalFolder = GetFolderPath("Archive\Done")

' change field values here
With objAppt
    .ReminderSet = False
    .Categories = ""
End With

    objAppt.Move CalFolder
 End Sub

Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
    Dim oFolder As Outlook.Folder
    Dim FoldersArray As Variant
    Dim i As Integer
        
    On Error GoTo GetFolderPath_Error
    If Left(FolderPath, 2) = "\\" Then
        FolderPath = Right(FolderPath, Len(FolderPath) - 2)
    End If
    'Convert folderpath to array
    FoldersArray = Split(FolderPath, "\")
    Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
    If Not oFolder Is Nothing Then
        For i = 1 To UBound(FoldersArray, 1)
            Dim SubFolders As Outlook.Folders
            Set SubFolders = oFolder.Folders
            Set oFolder = SubFolders.Item(FoldersArray(i))
            If oFolder Is Nothing Then
                Set GetFolderPath = Nothing
            End If
        Next
    End If
    'Return the oFolder
    Set GetFolderPath = oFolder
    Exit Function
        
GetFolderPath_Error:
    Set GetFolderPath = Nothing
    Exit Function
End Function

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
             
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
         
    Set objApp = Nothing
End Function

Move all appointments

This code sample moves all appointments with an End time before "Now", to the archive folder.

Public Sub MoveAllAppointments()
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objAppt As Outlook.Items
    Dim objFolder As Outlook.MAPIFolder
 
    On Error Resume Next
 
    Set objOL = CreateObject("Outlook.Application")
    Set objNS = objOL.GetNamespace("MAPI")
    Set objFolder = objNS.GetDefaultFolder(olFolderCalendar)
    Set objAppt = objFolder.Items
 
' move to a calendar in an archive data file
Set CalFolder = GetFolderPath("Archive\Done")

For i = objAppt.Count To 1 Step -1
  
If objAppt(i).End < Now Then
         
' change field values here
With objAppt(i)
    .ReminderSet = False
    .Categories = ""
End With

objAppt(i).Move CalFolder
    End If

Next i

    Set objAppt = Nothing
    Set objFolder = Nothing
    Set objOL = Nothing
    Set objNS = Nothing

    
 End Sub

Move Appointments to an Archive Calendar was last modified: September 19th, 2018 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Working with VBA and non-default Outlook Folders
  • Save appointments to a non-default Outlook calendar folder
  • This macro copies a meeting request to an appointment. Why would you w
    Copy meeting details to an Outlook appointment
  • VBA: Copy New Appointments to Another Calendar

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
17 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

stephengazard (@guest_175105)
March 25, 2013 3:20 am
#175105

perfect thanks

0
0
Reply
stephengazard (@guest_174925)
March 20, 2013 5:04 am
#174925

Sorry Diane I am sure I am being dum ... but I've done that but it appears to now run the process on the sub calendar "Call Log" rather than run the process on the default calendar and then move the appointment to the sub calendar on completion.

0
0
Reply
Diane Poremsky (@guest_174926)
Reply to  stephengazard
March 20, 2013 5:14 am
#174926

Oh, sorry about that. I misunderstood. You want to mark and move the appointments? You need to add this and the getfolderpath function. (It's in the first sample on this page too.)

This can go before the For each..
Set CalFolder = GetFolderPath("ArchiveDone")

And this after the .save but before the End if and Next lines.
objAppt.Move CalFolder

0
0
Reply
stephengazard (@guest_174912)
March 19, 2013 2:01 pm
#174912

Thanks Diane, .... how do I get the move to work to the sub calendar though? I can't get that to work.

0
0
Reply
Diane Poremsky (@guest_174916)
Reply to  stephengazard
March 19, 2013 3:23 pm
#174916

If the subcalendar is in the same data file as the calendar, you'd use

Set objCalendar = Session.GetDefaultFolder(olFolderCalendar).Folders("SharedCal")

instead of
Set objCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)

Working with other folders

0
0
Reply
stephengazard (@guest_174871)
March 18, 2013 1:26 am
#174871

Really? That part seems to work for me it is the move that doesn't.

If I wanted to replace the SQL then with an if stmt will tag help?

All the relevant appointments start with "C."

0
0
Reply
Diane Poremsky (@guest_174874)
Reply to  stephengazard
March 18, 2013 5:49 am
#174874

The Keyword was the problem - with that gone the filter works and the macro completes.

I ended up using this filter to speed things up as I have like 1500 appointments and it ran through each - I had added a msgbox location to see what the restriction was returning. :)
strRestriction = "@SQL= (""urn:schemas:httpmail:subject"" LIKE '@Call%' OR ""urn:schemas:httpmail:subject"" LIKE 'C%' AND %last7days(""urn:schemas:calendar:dtstart"")%)"

In this block:
For Each aItem In objCalendar.Items
If Mid(aItem.subject, 1, 2) = "C." Then

you don't identify what an aItem is.

I moved the subject editing code up into the If loop:

objAppt.Categories = "S. CALL MADE."
End If

' my tests had call as the first word
strTemp = Right(objAppt.Subject, (Len(objAppt.Subject) - 5))
objAppt.Subject = strTemp
MsgBox strTemp
iItemsUpdated = iItemsUpdated + 1

objAppt.Save

If the goal of this is to not process previously processed items, you could look for categories. (the location code allows for case variations on the case and spaces at the end.)
If InStr(1, Item.Categories) "Call" Then
If Left(LCase(objAppt.Location), 11) = "missed call" Then

You could check categories in the sql filter code instead of in the loop.

my version is at steve-macro.txt

0
0
Reply
stephengazard (@guest_174856)
March 17, 2013 1:52 pm
#174856

Yes works fine using SQL simply as I adapted from someone else code.

0
0
Reply
Diane Poremsky (@guest_174861)
Reply to  stephengazard
March 17, 2013 4:51 pm
#174861

It's failing here on the SQL (in the macro at least).

0
0
Reply
dporemsky (@guest_174850)
March 17, 2013 9:05 am
#174850

Does the SQL filter work as expected in custom views? Is there a reason you are using that filter instead of an If statement? If instr( item.subject, "call") then...

0
0
Reply
stephengazard (@guest_174758)
March 14, 2013 10:56 am
#174758

other code: Private Sub Application_Reminder(ByVal Item As Object) If Item.subject = "Process Calls" Then ' Define variables Dim objCalendar As Outlook.folder Dim objItems As Outlook.Items Dim objAppt As Outlook.AppointmentItem Dim strRestriction As String Dim objFinalItems As Outlook.Items Dim myolApp As Outlook.Application ' Set strRestriction to be only calls strRestriction = "@SQL= (""urn:schemas:httpmail:subject"" LIKE '@Call.%' OR ""urn:schemas:httpmail:subject"" LIKE 'C.%' OR ""urn:schemas:httpmail:subject"" LIKE '@Call in%' OR ""urn:schemas:httpmail:subject"" LIKE '@Call%') AND ""urn:schemas-microsoft-com:office:office#Keywords"" 'Phone call'" ' Set the objCalendar and objItems items Set objCalendar = Application.Session.GetDefaultFolder(olFolderCalendar) Set objItems = objCalendar.Items Set objFinalItems = objItems.Restrict(strRestriction) Set myolApp = CreateObject("Outlook.Application") For Each objAppt In objFinalItems ' Debugging ' Debug.Print objAppt.Start, objAppt.Subject, objAppt.Categories ' Assign the category to the appointments If objAppt.Location = "Missed Call " Then objAppt.Categories = "S. CALL MISSED." ElseIf objAppt.Location = "Incoming Call " Then objAppt.Categories = "S. CALL RECEIVED." Else objAppt.Categories = "S. CALL MADE." End If objAppt.Save Next ' Rename Entry Dim iItemsUpdated As Integer Dim strTemp As String iItemsUpdated = 0 For Each aItem In objCalendar.Items If Mid(aItem.subject, 1, 2) = "C." Then strTemp = Mid(aItem.subject, 4, Len(aItem.subject) - 4) aItem.subject = strTemp iItemsUpdated = iItemsUpdated + 1 End If aItem.Save Next aItem MsgBox iItemsUpdated & " of " &… Read more Âğ

0
0
Reply
stephengazard (@guest_174650)
March 12, 2013 3:20 am
#174650

Thanks Diane, I think I am getting there but struggling a bit .... I have two processes (I am sure the could be shortened to one mind you but everytime I try I break it !) ... First process sets category of appointment based on Subject and location (all works ok). The second process "MoveCallLog" should (but doesn't) ... move only those appointments that carry the category of "Calls" to a sub calendar called "Call Log" I can't get it to work - it either doesn't fire or moves everything! Also is there a way to automate more regularly than daily via the task reminder? Your help would be MUCH appreciated. Code below: Private Sub Application_Reminder(ByVal Item As Object) If Item.subject = "Move Calls" Then Public Sub MoveACallLog() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim objAppt As Outlook.Items Dim objFolder As Outlook.MAPIFolder On Error Resume Next Set objOL = CreateObject("Outlook.Application") Set objNS = objOL.GetNamespace("MAPI") Set objFolder = objNS.GetDefaultFolder(olFolderCalendar) Set objAppt = objFolder.Items ' move to a calendar in an archive data file Set CalFolder = GetFolderPath("\stephen@gazard.netCalendarCall Log") For i = objAppt.Count To 1 Step -1 If objAppt(i).Categories = "Calls" Then objAppt(i).Move CalFolder End If Next i Set objAppt… Read more Âğ

1
-1
Reply
Diane Poremsky (@guest_174678)
Reply to  stephengazard
March 12, 2013 8:52 pm
#174678

On the more regular part - you can set up more tasks with different reminder times. Add code to mark the task complete and save it, and recurring tasks will keep running. Otherwise, you need some way to trigger it since Outlook doesn't have a timer.

I think the code is probably not running, if its waiting for the first code to set the category. What is the full code for the other macro?

1
-1
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 22

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • How to Remove the Primary Account from Outlook
  • Adjusting Outlook's Zoom Setting in Email
  • Outlook: Web Bugs & Blocked HTML Images
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Move an Outlook Personal Folders .pst File
  • Create rules that apply to an entire domain
  • Use PowerShell to get a list of Distribution Group members
  • View Shared Calendar Category Colors
  • How to Create a Pick-a-Meeting Request
  • Remove a password from an Outlook *.pst File
  • Send Individual Messages when Sending Bulk Email
  • Centrally managed signatures in Office 365?
  • Create a rule to delete spam with no sender address
  • Open Outlook Folders using PowerShell or VBScript
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment