使用自定义名称创建 pst 文件

问题描述 投票:0回答:2

我正在使用以下代码创建一个新的 pst 文件。但 pst 文件是使用 Outlook 中的默认名称“Outlook 数据文件”创建的。我没有找到任何选项来设置新 pst 文件的名称。

Set objNS = objOutlook.GetNamespace("MAPI")
objNS.AddStoreEx "C:\Users\pitarr\Documents\Outlook Files\f23.pst",2

vbscript outlook
2个回答
0
投票

尝试调用您添加的数据存储返回的 PropertyAccessor 对象的 SetProperty 方法。例如:

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

否则,看看重命名商店的根文件夹是否就足够了,正如Lankymart建议的那样:

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

顺便说一句,上面的两个示例都未经测试,可能取决于所使用的编码。

希望这有帮助。


0
投票
 Sub bt_newpst_Click()
    Dim olApp As Outlook.Application
    Dim ns As Outlook.Namespace
    
    Set olApp = CreateObject("Outlook.Application")
    Set ns = olApp.GetNamespace("MAPI")
    ns.AddStore "D:\Test\" & CStr("TypeName") & ".pst"
    ilast = ns.Session.Folders.Count
    MsgBox ns.Session.Folders.Item(ilast)
    
    Set ns = Nothing
    
    End Sub
© www.soinside.com 2019 - 2024. All rights reserved.