23 September 2014

How To Recreate the Birthday and Anniversary reminders in the Outlook Calendar

Here is how to recreate the Birthday and Anniversary reminders in the Outlook Calendar. Put this macro code in Outlook MVA Editor (Alt-F11) and run.

Sub olRobot()
' Outlook VBA script by Sergii Vakula
' Auto generation the Birthdays and Anniversaries appointments of all Contact folders to a specific calendar
' Auto changing Contact's FileAs fields: FullName for humans, CompanyName for companies

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objItems As Outlook.Items
Dim obj As Object
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")

On Error Resume Next

' *****************************************************************************************************
' *** STAGE 1: Rebuilding Contact's Birthdays and Anniversaries to the main calendar, fixing FileAs ***
' *****************************************************************************************************

Dim Report As String
Dim mySession As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Set mySession = Application.Session

' Method 1: Ask for Contact folder
'MsgBox ("Select Contact folder by next step...")
'Call ContactsFolders(Session.PickFolder, Report)

' Method 2: Use default Contact folder and all subfolders
'Call ContactsFolders(objNS.GetDefaultFolder(olFolderContacts), Report)

' Method 3: Use all Contact folders
For Each myFolder In mySession.Folders
Call ContactsFolders(myFolder, Report)

' ***************************************************************************************
' *** STAGE 2: Moving Birthdays and Anniversaries appointments to a specific calendar ***
' ***************************************************************************************

Dim objCalendar As Outlook.AppointmentItem
Dim objCalendarFolder As Outlook.MAPIFolder
Dim cAppt As AppointmentItem
Dim moveCal As AppointmentItem
Dim pattern As RecurrencePattern
Set objCalendarFolder = objNS.GetDefaultFolder(olFolderCalendar)
bodyMessage = "This is autocreated appointment"

' Method 1: Ask for specific calendar folder for birthdays and anniversaries
'MsgBox ("Select Birthdays and Anniversaries Calendar folder by next step...")
'Set newCalFolder = Session.PickFolder

' Method 2: Use pre-assigned calendar folder for birthdays and anniversaries
'Set newCalFolder = GetFolderPath("display name in folder listCalendarBirthdays and Anniversaries")
Set newCalFolder = GetFolderPath("\sv@pbxsphere.comCalendarBirthdays and Anniversaries")

For i = newCalFolder.Items.Count To 1 Step -1
Set obj = newCalFolder.Items(i)
If obj.Class = olAppointment And _
obj.GetRecurrencePattern.RecurrenceType = olRecursYearly And _
obj.AllDayEvent And _
obj.Body = bodyMessage Then
Set objCalendar = obj
End If

For i = objCalendarFolder.Items.Count To 1 Step -1
Set obj = objCalendarFolder.Items(i)
If obj.Class = olAppointment And _
obj.GetRecurrencePattern.RecurrenceType = olRecursYearly And _
obj.AllDayEvent And _
(Right(obj.Subject, 11) = "'s Birthday" Or Right(obj.Subject, 14) = "'s Anniversary" Or _
Right(obj.Subject, 13) = "???? ????????" Or Right(obj.Subject, 9) = "?????????") Then

Set objCalendar = obj
Set cAppt = Application.CreateItem(olAppointmentItem)

With cAppt
.Subject = objCalendar.Subject
.Start = objCalendar.Start
.Duration = objCalendar.Duration
.AllDayEvent = True
.Body = bodyMessage
.ReminderSet = False
.BusyStatus = olFree
End With

Set pattern = cAppt.GetRecurrencePattern
pattern.RecurrenceType = olRecursYearly


Set moveCal = cAppt.Move(newCalFolder)
'moveCal.Categories = "moved"

End If

Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objCalendar = Nothing
Set objCalendarFolder = Nothing
Set cAppt = Nothing
Set moveCal = Nothing
Set pattern = Nothing
Set mySession = Nothing
Set myFolder = Nothing

MsgBox ("Completed!" & vbCrLf & vbCrLf & "All Contact's FileAs were fixed." & vbCrLf & "All Birthdays and Anniversaries appointments were re-created." & vbCrLf & vbCrLf & "Contact folders that been processed:" & vbCrLf & Report & vbCrLf & "Calendar for Birhdays and Anniversaries:" & vbCrLf & newCalFolder.FolderPath & vbCrLf & vbCrLf & "Have a nice day!")

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
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
End If
Set GetFolderPath = oFolder
Exit Function
Set GetFolderPath = Nothing
Exit Function
End Function

Private Sub ContactsFolders(CurrentFolder As Outlook.Folder, Report As String)
Dim objItems As Outlook.Items
Dim obj As Object
Dim objContact As Outlook.ContactItem
Dim strFileAs As String
Dim SubFolder As Outlook.Folder
Dim SubFolders As Outlook.Folders
Set SubFolders = CurrentFolder.Folders
If CurrentFolder.DefaultItemType = 2 Then
Report = Report & CurrentFolder.FolderPath & vbCrLf
Set objItems = CurrentFolder.Items
For Each obj In objItems
If obj.Class = olContact Then
Set objContact = obj

With objContact

If .FullName = "" Then
strFileAs = .CompanyName
strFileAs = .FullName
End If

.FileAs = strFileAs

mybirthday = .Birthday
myanniversary = .Anniversary
.Birthday = Now
.Anniversary = Now
.Birthday = mybirthday
.Anniversary = myanniversary

.Close 0
End With

End If

End If

For Each SubFolder In SubFolders
Call ContactsFolders(SubFolder, Report)

Set SubFolder = Nothing
Set SubFolders = Nothing

End Sub

17 September 2014

Best monetize model for Windows Phone/Store Apps

Free version with ads
paid version with try option

29 July 2014

How to disable Frame Rate Counter in Windows 8 Applications

To disable Frame Rate Counter in Windows 8 Applications there should enter next line in MainPage.xaml.cs on public MainPage() method :

public MainPage()
            Application.Current.DebugSettings.EnableFrameRateCounter = false;

23 July 2014

Windows Phone 8 and SQLite deploy to device error

On the Build tab, you’ll see Conditional compilation symbols under the General header, containing a default value of SILVERLIGHT;WINDOWS_PHONE on a Windows Phone app project. Change the value to SILVERLIGHT;WINDOWS_PHONE;USE_WP8_NATIVE_SQLITE and save the project file.

22 April 2014

MS Windows 8.1 : Add shortcut to This PC Explorer sidebar

I'm going to share a very small and easy trick which can be used to add any desired shortcut, file or folder in This PC Explorer sidebar in MS Windows 8.1.

Type following string in RUN (Win+R) or start menu search box and press Enter:
%AppData%\Microsoft\Windows\Network Shortcuts
It'll open "Network Shortcuts" folder.
You can also directly open the same folder by typing Network Shortcuts in Explorer addressbar and press Enter.
Now what you have to do is simply create shortcut to the desired folder and PASTE it in this "Network Shortcuts" folder. You can also paste file shortcuts or simply move the original file in this folder. 

06 April 2014

Microsoft Visual Studio development versions and target platforms

It's a little bit confusing to choose which version of Visual Studio is for desired Windows Phone or Windows Store platform. So I create this table :

MS Windows Phone 7
MS Visual Studio 2010 Express for Windows Phone

MS Visual Studio 2012 Express for Windows Phone
MS Windows Phone 8
MS Visual Studio 2012 Express for Windows Phone
MS Windows Phone 8.1
MS Visual Studio 2013 Express for Windows Update 2 RC
MS Windows 8 Store Application
MS Visual Studio 2012 Express for Windows
MS Windows 8.1 Store Application
MS Visual Studio 2013 Express for Windows Update 2 RC

30 January 2014

Install Indy components into Lazarus

To have internet or server time in your application, you must install Indy components.
For a lot of users, I'm sure that the information given above won't work, or will be somewhat confusing given the differences between versions and inconsistent explanations.

The website points you to download the latest version from the snapshots page.
This wiki tells you to copy a lot of files over into directories.For me, neither worked, and ended up making a mess of my Lazarus installations.
  • Firstly, the page I would retrieve this from is here. Other sites I tried had problems with some files inside the archive.
  • When you open up the archive above, you will see there are folders: "fpc" and "lazarus".
  • You can copy the contents of "fpc" into: LAZARUS_DIR\fpc\2.6.0\source\packages\indylaz if you want to have things neat and tidy.
  • The "lazarus" folder, you copy into LAZARUS_DIR\components\indylaz
  • With both of these, make sure that there isn't a sub-directory inside the folders given. i.e. LAZARUS_DIR\components\indylaz\lazarus\
  • Go into Lazarus and go to "Package" -> "Open package file" and point it to the "indylaz.lpk" inside the LAZARUS_DIR\components\indylaz directory.
  • Once the package loads inside your project, click on the "options" button, which resembles an image of a parcel with a cog next to it.
  • Click the "Compiler Options" on the left-hand side and Click on the ".." button next to "Other unit files (-Fu) (delimiter is semicolon)". Select the "fpc" folder you created above and click OK. Lazarus will sort out the relative path for you. Don't change it.
  • Click OK and compile and then direct angry bile towards the individual who has steered you wrong with the previous, unhelpful, instructions.
  • Compile then install (will rebuild Lazarus). 
  • Currently, due to a know bug in FPC, you must compile the Indy package TWICE before installing it.