0
첫 번째 게시물을 반복 그러면 이메일에서 추가 로직을 수행 할 수 있습니다. 그러나 정크 박스 또는 기본이 아닌 계정의받은 편지함을 참조하는 방법을 파악할 수 없기 때문에 계정 체크가 설정된 경우에도 내 코드가 내 기본 계정을 계속 사용합니다.전망 VBA 전환은 내가 그렇게받은 편지함에 비 기본 전망 계정의 정크 메일 폴더에있는 모든 이메일을 덤프 시도하고</p> <p>... 그래서 나와 함께 베어하시기 바랍니다 여기에 이메일을 통해
Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
dim lngCount as long
lngcount = 0
For Each oAccount In Application.Session.Accounts ' cycle through accounts till we find the one we want
If oAccount = "[email protected]" Then
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderJunk) ' select junk folder of the account
Set objDestFolder = objNamespace.GetDefaultFolder(olFolderInbox) ' select inbox of the account
For lngCount = objSourceFolder.Items.Count To 1 Step -1 ' Go through all items in inbox, if a mail object, move into inbox
Set objVariant = objSourceFolder.Items.Item(dblCount)
DoEvents
If objVariant.Class = olMail Then
Set objCurrentEmail = objVariant ' the inbox item is an email, so change object type to olMail (email object)
objCurrentEmail.Categories = "red category"
objCurrentEmail.Move objDestFolder ' Move the email to the required folder
End If
Next
End If
Next
End Sub
편집 : 에릭의 대답 후 나는 지금 작업 코드를 공유하고 싶습니다.
Private Sub clearJunk()
Dim objVariant As Variant ' Variant object to handle and inbox item
Dim objCurrentEmail As Outlook.MailItem ' Temporary email object for logic
Dim dblCount As Double ' Double used to count email items in the inbox
Dim objStore As Outlook.Store ' Store Object to cycle through email accounts
Dim objRoot As Outlook.Folder ' Folder object to define Inbox of desired account
Dim folders As Outlook.folders ' FolderS object to holder folders...lol
Dim Folder As Outlook.Folder ' Temporary Folder object
Dim foldercount As Integer ' integer to count folders in account
Dim objInboxFolder As Outlook.MAPIFolder ' MAPI folder object to move emails to or from
Dim objJunkFolder As Outlook.MAPIFolder ' MAPI folder object to move emails to or from
Dim objRandomFolder As Outlook.MAPIFolder ' MAPI folder object to move emails to or from
'--------------------------------------------------------------------
' Cycle through each account in outlook client and find desired account
For Each objStore In Application.Session.Stores
If objStore = "[email protected]" Then ' If we find the account
Set objRoot = objStore.GetRootFolder ' Store int objRoot Object
On Error Resume Next
Set folders = objRoot.folders ' Check if it has folders
foldercount = folders.Count
If foldercount Then ' if folders exist
For Each Folder In folders ' Go through each folder AND ....
' Look for Junk Email folder, Inbox Folder, and some random customer folder.
' Store in individual objects for future referencing
If Folder.FolderPath = "\\[email protected]\Junk Email" Then
Set objJunkFolder = Folder
End If
If Folder.FolderPath = "\\[email protected]\Inbox" Then
Set objInboxFolder = Folder
End If
If Folder.FolderPath = "\\[email protected]\Random Custom Folder" Then
Set objRandomFolder = Folder
End If
Next
End If
' Now we have everything identified lets move emails!
For dblCount = objJunkFolder.Items.Count To 1 Step -1
Set objVariant = objJunkFolder.Items.Item(dblCount)
DoEvents
If objVariant.Class = olMail Then
Set objCurrentEmail = objVariant
objCurrentEmail.Categories = "Red Category"
objCurrentEmail.Move objInboxFolder
End If
Next
End If
Next
End Sub
굉장! 확실한 방향으로 이끌어주는 저! 원래 게시물을 편집하여 모든 사람들에게 내가 어떻게 작동하는지 보여주고, 여러 번 이것을 100 % 성공으로 돌 렸습니다. 에릭 감사합니다. – zicon117