Skip to content

Instantly share code, notes, and snippets.

@mattocchi
Created February 4, 2017 09:37
Show Gist options
  • Save mattocchi/653969512de692b1015f7f2aed45d59a to your computer and use it in GitHub Desktop.
Save mattocchi/653969512de692b1015f7f2aed45d59a to your computer and use it in GitHub Desktop.
Nokia PCSuite and Outlook (Sync Other Phone Number issue)
' Code for post this http://mircoattocchi.blogspot.it/2009/01/nokia-pcsuite-and-outlook-other-phone.html
Sub CorrectNokiaContacts()
  ' This procedure retrieves all contacts from the Outlook
  ' Contacts folder and for eatch Contact move the
  ' OtherTelephoneNumber content on MobileTelephoneNumber or BusinessTelephoneNumber
  ' based on how OtherTelephoneNumber ("3" or "+393" or "+39 3")
  ' when MobileTelephoneNumber and BusinessTelephoneNumber are empty.
  '
  ' Configure your Area Code:
  Dim AreaCode As String
  AreaCode = "+39"
 
  Dim olapp           As Outlook.Application
  Dim nspNameSpace    As Outlook.NameSpace
  Dim fldContacts     As Outlook.MAPIFolder
  Dim objContacts     As Object
  Dim objContact      As Outlook.ContactItem 'Object
  Dim intCntr         As Integer
  Dim strZLS          As String
 
  Dim strAction As Variant
  Dim objIE As Object
  Dim objDoc As Object
 
  On Error GoTo GetAll_Err
 
  If (MsgBox("Are you sure to move OtherTelephoneNumber field for all contacts?", vbOKCancel) = vbCancel) Then Exit Sub
 
  ' Get reference to the Outlook Contacts folder.
  Set olapp = New Outlook.Application
  Set nspNameSpace = olapp.GetNamespace("MAPI")
  Set fldContacts = nspNameSpace.GetDefaultFolder(olFolderContacts)
  Set objContacts = fldContacts.Items
 
  For Each objContact In objContacts
 
      If (Len(objContact.OtherTelephoneNumber) > 0) Then
          ' Apply OtherTelephoneNumber Rule
          If (Left(objContact.OtherTelephoneNumber, 1) = "3" Or _
              Left(objContact.OtherTelephoneNumber, 4) = AreaCode & "3" Or _
              Left(objContact.OtherTelephoneNumber, 5) = AreaCode & " 3") Then
              ' Move to MobileTelephoneNumber
              If Not (Len(objContact.MobileTelephoneNumber) > 0) Then
                  objContact.MobileTelephoneNumber = objContact.OtherTelephoneNumber
                  objContact.OtherTelephoneNumber = ""
                  objContact.Save
                 
                  strAction = strAction & objContact.FullName & ": " & objContact.OtherTelephoneNumber & " -> MobileTelephoneNumber" & vbCrLf
                  intCntr = intCntr + 1
              End If
          Else
              ' Move to BusinessTelephoneNumber
              If Not (Len(objContact.BusinessTelephoneNumber) > 0) Then
                  objContact.BusinessTelephoneNumber = objContact.OtherTelephoneNumber
                  objContact.OtherTelephoneNumber = ""
                  objContact.Save
                 
                  strAction = strAction & objContact.FullName & ": " & objContact.OtherTelephoneNumber & " -> BusinessTelephoneNumber" & vbCrLf
                  intCntr = intCntr + 1
              End If
          End If
      End If
 
  Next objContact
 
  ' Copy a log to clipboard
  Set objIE = CreateObject("InternetExplorer.Application")
  objIE.navigate ("about:blank")
  Set objDoc = objIE.Document
  varResult = objDoc.parentWindow.clipboardData.setData("Text", strAction)
 
  MsgBox "Total modifed Contacts: " & intCntr & " of " & objContacts.Count & vbCrLf & _
  "On clipboard there is a log of modified Contacts"
 
  Set objIE = Nothing
  Set objDoc = Nothing
 
GetAll_Bye:
  Exit Sub
GetAll_Err:
  MsgBox Err.Description, vbOKOnly, "Error = " & Err.Number
  Resume GetAll_Bye
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment