Advertisement
gn4711

Outlook Appointment Categorizer

Dec 9th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Private Sub Application_Reminder(ByVal Item As Object)
  4.  
  5.     If Item.MessageClass <> "IPM.Appointment" Then
  6.       Exit Sub
  7.     End If
  8.      
  9.     Dim Appt As AppointmentItem
  10.     Dim Items As Object
  11.    
  12.     Set Items = Session.GetDefaultFolder(olFolderCalendar).Items
  13.      
  14.     For Each Appt In Items
  15.      
  16.         On Error Resume Next
  17.          
  18.         If InStr(Appt.Subject, "Trip - KW") > 0 Or _
  19.            InStr(Appt.Subject, "Hotel - ") > 0 Or _
  20.            InStr(Appt.Subject, "Car Pick-Up") > 0 Or _
  21.            InStr(Appt.Subject, "Car Drop-Off") > 0 Or _
  22.            InStr(Appt.Subject, "Abreise") > 0 Or _
  23.            InStr(Appt.Subject, "Anreise") > 0 Or _
  24.            InStr(Appt.Subject, "Flight AB") > 0 Or _
  25.            InStr(Appt.Subject, "Flight LH") > 0 Then
  26.        
  27.             If InStr(Appt.Categories, "Reise") = 0 Then
  28.                 Appt.Categories = "Reise;" & Appt.Categories
  29.                 Appt.Save
  30.             End If
  31.         End If
  32.        
  33.         If InStr(Appt.Subject, "WW Communities") > 0 Or _
  34.            InStr(Appt.Subject, "Invite - ") > 0 Then
  35.        
  36.             If InStr(Appt.Categories, "20_Orga/Learning") = 0 Then
  37.                 Appt.Categories = "20_Orga/Learning;" & Appt.Categories
  38.                 Appt.Save
  39.             End If
  40.         End If
  41.      
  42.     Next
  43.      
  44.     Beep
  45.    
  46.  
  47. End Sub
  48.  
  49.  
  50.  
  51. Public Sub remove_extension()
  52.  
  53.     Dim app As Outlook.Application
  54.     Set app = CreateObject("Outlook.Application")
  55.    
  56.     Dim ns As Outlook.NameSpace
  57.     Set ns = app.GetNamespace("MAPI")
  58.     ns.Logon
  59.    
  60.     Dim contacts As Outlook.MAPIFolder
  61.     Set contacts = ns.GetDefaultFolder(olFolderContacts)
  62.    
  63.     Dim Item As Outlook.ContactItem
  64.     Dim sDisplayAs As String
  65.         Dim rx As New RegExp
  66.     rx.IgnoreCase = True
  67.     rx.Pattern = "\s*X\d+"
  68.        
  69.     For Each Item In contacts.Items
  70.         Dim s As String
  71.         s = rx.Replace(Item.BusinessTelephoneNumber, "")
  72.         If (s <> Item.BusinessTelephoneNumber) Then
  73.             Item.BusinessTelephoneNumber = s
  74.             Item.Save
  75.         End If
  76.        
  77.     Next
  78.     Beep
  79. End Sub
  80.  
  81.  
  82. Public Sub format_display_name()
  83.  
  84.     Dim app As Outlook.Application
  85.     Set app = CreateObject("Outlook.Application")
  86.    
  87.     Dim ns As Outlook.NameSpace
  88.     Set ns = app.GetNamespace("MAPI")
  89.     ns.Logon
  90.    
  91.     Dim contacts As Outlook.MAPIFolder
  92.     Set contacts = ns.GetDefaultFolder(olFolderContacts)
  93.    
  94.     Dim Item As Outlook.ContactItem
  95.     Dim sDisplayAs As String
  96.    
  97.     For Each Item In contacts.Items
  98.    
  99.         sDisplayAs = ""
  100.    
  101.         If (Len(Item.FirstName) * Len(Item.LastName) > 0) Then
  102.             sDisplayAs = Item.LastName + ", " + Item.FirstName
  103.         Else
  104.             sDisplayAs = Item.FileAs
  105.         End If
  106.            
  107.         If Item.CompanyName = "GERMANY" Then
  108.             sDisplayAs = sDisplayAs + " (Microsoft)"
  109.             Item.CompanyName = "Microsoft"
  110.         ElseIf Len(Item.CompanyName) > 0 Then
  111.             sDisplayAs = sDisplayAs + " (" + Item.CompanyName + ")"
  112.         End If
  113.        
  114.        
  115.         If (Len(sDisplayAs) > 0) Then
  116.             Item.Email1DisplayName = sDisplayAs
  117.             Item.Save
  118.         End If
  119.      
  120.     Next
  121.     Beep
  122.  End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement