vba 如何找到 Outlook .pst 文件的完整路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/195849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 09:59:06  来源:igfitidea点击:

How to find full path of Outlook .pst file?

winapivbaoutlookregistrypst

提问by Vic

Is there a way to programmatically find the location of the current user's Outlook .pst file(s) through an API call or registry entry?

有没有办法通过 API 调用或注册表项以编程方式查找当前用户的 Outlook .pst 文件的位置?

采纳答案by Tomalak

With Outlook Redemption, you can iterate the message stores in VBA using RDOStorescollection, accessible via the RDOSession.Storesproperty.

使用Outlook Redemption,您可以使用RDOStores集合迭代 VBA 中的消息存储,可通过RDOSession.Stores属性访问。

I am looking into the possibility of doing something similar in out-of-the-box VBA...

我正在研究在开箱即用的 VBA 中做类似事情的可能性......

EDIT:

编辑:

Obviously, the path to the PST is encoded in the StoreId string. Google turned up this:

显然,到 PST 的路径编码在 StoreId 字符串中。谷歌发现了这个

Sub PstFiles()
  Dim f As MAPIFolder

  For Each f In Session.Folders
    Debug.Print f.StoreID
    Debug.Print GetPathFromStoreID(f.StoreID)
  Next f
End Sub

Public Function GetPathFromStoreID(sStoreID As String) As String
  On Error Resume Next
  Dim i As Long
  Dim lPos As Long
  Dim sRes As String

  For i = 1 To Len(sStoreID) Step 2
    sRes = sRes & Chr("&h" & Mid$(sStoreID, i, 2))
  Next

  sRes = Replace(sRes, Chr(0), vbNullString)
  lPos = InStr(sRes, ":\")

  If lPos Then
    GetPathFromStoreID = Right$(sRes, (Len(sRes)) - (lPos - 2))
  End If
End Function

Just tested, works as designed.

刚刚测试,按设计工作。

回答by Node

The path should be somewhere under:

路径应该在以下某处:

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook]

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook]

Maybe this helps a bit.

也许这有点帮助。