I am creating a new pst file using the below code. But the pst file is created with the default name of "Outlook Data File" in Outlook. I don't find any option to set the name of the new pst file.
Set objNS = objOutlook.GetNamespace("MAPI")
objNS.AddStoreEx "C:\Users\pitarr\Documents\Outlook Files\f23.pst",2
Try calling the SetProperty method of the PropertyAccessor object returned by the data Store you added. For example:
Const PR_DISPLAY_NAME = "http://schemas.microsoft.com/mapi/proptag/0x3001001F"
Dim oStore, oPA
For Each oStore in objNS.Stores
If oStore.FilePath = "C:\Users\pitarr\Documents\Outlook Files\f23.pst" Then
Set oPA = oStore.PropertyAccessor
oPA.SetProperty PR_DISPLAY_NAME, "SomeNewName"
End If
Next
Otherwise, see if renaming the root folder of the store is sufficient, as Lankymart suggests:
Dim oStore, oFolder
For Each oStore in objNS.Stores
If oStore.FilePath = "C:\Users\pitarr\Documents\Outlook Files\f23.pst" Then
Set oFolder = oStore.GetRootFolder()
oFolder.Name = "SomeNewName"
End If
Next
BTW, both examples above are untested, and may be dependent upon the encoding used.
Hope this helps.