Sub CreateBackupFiles()
Dim OlApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim copyToDataFile As Outlook.folder
Dim copyFrom As Outlook.folder
Dim myBackup As Outlook.folder
Dim objFolder As Outlook.folder
Dim folderType
Dim enviro As String, strDate As String
Dim strFileName As String, pstName As String
Set objNS = Application.GetNamespace("MAPI")
enviro = CStr(Environ("USERPROFILE"))
strDate = Format(Date, "yyyymmdd") & Format(Time, "hhmmss")
strFileName = enviro & "\Documents\Outlook Files\" & strDate & "-BackUp" & ".pst"
pstName = "Backup " & strDate
Debug.Print strFileName
' Create the backup pst file
objNS.AddStore strFileName
Set objFolder = objNS.Folders.GetLast
objFolder.Name = pstName
Set copyToDataFile = objFolder
For i = 1 To 4
Select Case i
Case 1
folderType = olFolderCalendar
Value = "IPF.Appointment"
Case 2
folderType = olFolderContacts
Value = "IPF.Contact"
Case 3
folderType = olFolderTasks
Value = "IPF.Task"
Case 4
folderType = olFolderNotes
Value = "IPF.StickyNote"
End Select
Set copyFrom = objNS.GetDefaultFolder(folderType)
Set myBackup = copyFrom.CopyTo(copyToDataFile)
Next i
' remove the pst from the folder list
'objNS.RemoveStore objFolder
Set oPA = Nothing
Set objNS = Nothing
End Sub