首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何指向替代.pst的文件夹?

如何指向替代.pst的文件夹?
EN

Stack Overflow用户
提问于 2019-08-06 08:37:40
回答 2查看 309关注 0票数 2

我找不到完全在Excel VBA之外操作的代码,无法指向Outlook中非默认收件箱的收件箱。

想象一下第二个收件箱,有一个替代的电子邮件地址来存放特殊的电子邮件。

似乎Set Inbox = Ns.GetDefaultFolder(olFolderInbox)是在适当的代码中进行更改的自然位置。一些建议涉及使用parent.folder,但这似乎不起作用。

假设备选收件箱的名称为"New Orders“

我试过Set Inbox = Ns.GetDefaultFolder(6).Parent.Folders("New Orders")

EN

回答 2

Stack Overflow用户

发布于 2019-08-06 09:33:49

那样不行。您基本上要做的是查找与Inbox文件夹具有相同层次结构的另一个文件夹(在相同的帐户或电子邮件上),而不是另一个帐户中的另一个文件夹。

...with特殊电子邮件的备用电子邮件地址...

在上面的例子中尝试使用这个(我使用了早期绑定):

代码语言:javascript
运行
复制
Dim oOL As Outlook.Application
Dim oAcc As Outlook.Account
Dim oStore As Outlook.Store
Dim oFolder As Outlook.Folder

Set oOL = GetObject(, "Outlook.Application")

For Each oAcc In oOL.Session.Accounts
  If oAcc.UserName = "User.Name" Then 
  '// Note: you can use other properties, I used this for demo //
    Set oStore = oAcc.DeliveryStore
    Set oFolder = oStore.GetDefaultFolder(olFolderInbox)
    Set oFolder = oFolder.Parent.Folders("New Oders")
  End If
Next

首先,您可以尝试运行For Loop来检查您是否真的有两个帐户。一旦经过验证,您就可以继续使用它了。HTH。

票数 0
EN

Stack Overflow用户

发布于 2019-08-08 19:50:34

HTH,谢谢你的建议。我已经尝试将其合并到我的代码中。不幸的是,我被留在了同样的位置。我在4kb的目标文件夹中未收到具有正确命名约定的空白文件

这是我的,所以far..perhaps,你可以在上下文中看到我的错误。

代码语言:javascript
运行
复制
Option Explicit

Sub Get_IOVFs()


Dim outlookInbox            As Outlook.MAPIFolder
Dim Item                    As Object
Dim outlookAttachment       As Outlook.Attachment
Dim attachmentFound         As Boolean
Dim attachmentName          As String
Const saveToFolder          As String = "C:\Users\Wassej03\Documents\IOVFs_Master"
Const attName               As String = "IOVF "
Dim TimeExt                 As String
Dim SavePath                As String
Dim ExtString               As String
Dim Filename                As String
Dim I                       As Integer

Dim oOL As Outlook.Application
Dim oAcc As Outlook.Account
Dim oStore As Outlook.Store
Dim oFolder As Outlook.Folder

Set oOL = GetObject(, "Outlook.Application")

For Each oAcc In oOL.Session.Accounts
  If oAcc.UserName = "ccIOVF@zoetis.com" Then
  '// Note: you can use other properties, I used this for demo //
    Set oStore = oAcc.DeliveryStore
    Set oFolder = oStore.GetDefaultFolder(olFolderInbox)
    Set oFolder = oFolder.Parent.Folders("Diagnostics Orders")
  End If
Next

TimeExt = format(Now, "dd-mmm-yy h-mm")
attachmentName = attName & TimeExt

'Get the inbox from Outlook
Dim NS As Outlook.Namespace
Dim objOwner As Outlook.Recipient

'Move to the alternative email Inbox
Set NS = oOL.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("cciovf@zoetis.com")
    objOwner.Resolve
Set outlookInbox = NS.GetSharedDefaultFolder(objOwner, olFolderInbox)

'Make sure that file extension at the end of this line is correct
SavePath = saveToFolder & "\" & attachmentName & ".xlsm"

'Loop through each email to save its attachment
I = 0
For Each Item In outlookInbox.Items
    For Each outlookAttachment In Item.Attachments
    If LCase(Right(outlookAttachment.Filename, Len(ExtString))) = LCase(ExtString) Then
                Filename = SavePath
                outlookAttachment.SaveAsFile Filename
                I = I + 1
             End If
        Next outlookAttachment
    Next Item


MsgBox "IOVFs were searched and if found are saved to '" & saveToFolder & "'!", vbInformation

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57367528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档