我有一个代码来移动一个邮件到一个文件夹创建的名称为加速人。但是我有4个不同的邮件银行/帐户(一个使用".fr",第二个使用".com"..),默认情况下,文件夹都是在第一个和主帐户中创建的(并且邮件被移动),所以我的邮件是混合的。
实际使用的代码为:
设置myRoot = Session.GetDefaultFolder(olFolderInbox)
我试图查看VBA outlook宏界面中的对象资源管理器,但我只找到了Getdefaultfolder (在命名空间或存储类中),我并不真正理解它。我没有找到“会话”的东西,除了实际的代码之外,似乎没有任何东西可以有效地编译。
你知道我的代码在与所选邮件相同的“邮件库”中工作吗?非常感谢!
Overflowly,Keyo
发布于 2020-06-21 02:51:26
您似乎需要将Outlook项目移动到同一存储区中的文件夹。Store.GetDefaultFolder方法返回一个Folder对象,该对象表示存储区中的默认文件夹,其类型由FolderType参数指定。此方法类似于NameSpace对象的GetDefaultFolder方法。不同之处在于,此方法获取与帐户关联的传递存储上的默认文件夹,而NameSpace.GetDefaultFolder返回当前配置文件的默认存储上的默认文件夹。
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)
Dim folders As Outlook.folders
Dim Folder As Outlook.Folder
Dim foldercount As Integer
On Error Resume Next
Set folders = oFolder.folders
foldercount = folders.Count
'Check if there are any folders below oFolder
If foldercount Then
For Each Folder In folders
Debug.Print (Folder.FolderPath)
EnumerateFolders Folder
Next
End If
End Sub因此,您需要找到与加速器(电子邮件)相对应的商店实例,并将项目移动到那里。
发布于 2020-06-23 01:38:31
使用.Parent从已知项目向上工作到它所在的文件夹,再到上面的文件夹,直到收件箱。
Option Explicit ' Consider this mandatory
' Tools | Options | Editor tab
' Require Variable Declaration
'
' If desperate declare as variant
Sub selectionParent()
Dim currItem As Object ' not mailitem
Dim curFolder As Folder
Dim myRoot As Folder
' select a mailitem in an inbox or subfolder of an inbox
Set currItem = ActiveExplorer.Selection(1)
If currItem.Class = olMail Then
Debug.Print
Debug.Print currItem.Subject
Set curFolder = currItem.Parent
' safest to compare text after LCase or UCase
Do Until LCase(curFolder.name) = LCase("inbox")
Debug.Print " curFolder.name: " & curFolder.name
Set curFolder = curFolder.Parent
Loop
' This is the inbox folder associated with the selected item
Set myRoot = curFolder
Debug.Print " myRoot: " & myRoot
Debug.Print " The mailbox is myRoot.Parent: " & myRoot.Parent
Else
Debug.Print
Debug.Print "** not a mailtem **"
End If
End Sub实际上,Session等同于GetNamespace("MAPI")。节省一些代码行。
这三个版本中的任何一个都会产生相同的结果。
Private Sub session_LineSaver_NamespaceMapi()
Dim inboxFldr As Folder
Debug.Print
Debug.Print "Session"
Set inboxFldr = Session.GetDefaultFolder(olFolderInbox)
Debug.Print " inboxFldr: " & inboxFldr
Debug.Print " inboxFldr.Parent: " & inboxFldr.Parent
Debug.Print
Debug.Print "GetNamespace - not best practice, harder to see errors"
Set inboxFldr = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Debug.Print " inboxFldr: " & inboxFldr
Debug.Print " inboxFldr.Parent: " & inboxFldr.Parent
Debug.Print
Debug.Print "GetNamespace - create a separate object for the namespace"
Dim nS As Namespace ' extra line
Set nS = GetNamespace("MAPI") ' extra line
Set inboxFldr = nS.GetDefaultFolder(olFolderInbox)
Debug.Print " inboxFldr: " & inboxFldr
Debug.Print " inboxFldr.Parent: " & inboxFldr.Parent
End Subhttps://stackoverflow.com/questions/62489229
复制相似问题