2011-04-21 5 views
0

Outlook에서 수식을 통해 사용자 지정 필드를 만들고 제목 필드를 구문 분석했습니다. 나는 이제 새로운 걸림돌을 때렸다. 맞춤 입력란은 정렬 할 수 없습니다. 이를 달성하기위한 유일한 방법은 새로운 user property을 생성하는 것이고, 이는 정렬이 가능하고 필드를 정의 할 때 활용 될 수 있습니다.수식으로 채워지는 Outlook에서 사용자 지정 정렬 가능 필드를 만들려면 어떻게해야합니까?

interop을 사용하여 VBA 스크립트 나 C# 응용 프로그램으로 모든 것을 푸시하는 옵션도 있습니다. 어느 쪽이든 나를 위해 일할 것이지만 나는 VBA 경로를 가서 자기가 포함 된 유지하는 것이 좋습니다.

전자 메일은 폴더에 있으며 사실 이후에 실행할 수 있습니다. 솔루션은 계속해서 활성화 될 필요가 없습니다.

누구든지 나를 쉽게 달성 할 수있는 코드를 가리킬 수 있다면 좋을 것입니다. 사용자 정의 필드를 정렬 가능하게 만드는 옵션이 누락 된 경우 최종 목표 인 대안을 제공하십시오.

편집 : 이것은 내가 현재 가지고있는 것입니다

... 정렬 밖으로 Erroring

Sub SortCustomField() 

    Dim olApp As Outlook.Application 
    Dim objLotusInbox As Outlook.MAPIFolder 
    Dim objLotusInboxItems As Outlook.Items 
    Dim objNameSpace As Outlook.NameSpace 
    Dim objProperty As Outlook.UserDefinedProperty 


    Set olApp = CreateObject("Outlook.Application") 
    Set objNameSpace = olApp.GetNamespace("MAPI") 
    Set objLotusInbox = objNameSpace.GetDefaultFolder(olFolderInbox).Folders("Lotus Notes Inbox") 

    Set objLotusInboxItems = objLotusInbox.Items 
    objLotusInboxItems.Sort "[Notes2Outlook Created]", False 

    Set objLotusInboxItems = Nothing 
    Set objLotusInbox = Nothing 
    Set objNameSpace = Nothing 
    Set olApp = Nothing 

End Sub 

; 꽤 확실한 것은 명시된 필드가 From과 같은 다른 필드에서 작동하므로 사용자 정의 필드라는 사실 때문입니다.

UPDATE : 다시 Outlook으로 갈 때 약간의 땅을 만들어

그러나 실행 중에 정의 된 필드를 채우는 데 나타나지 않습니다.

Dim olApp As Outlook.Application 
    Dim objLotusInbox As Outlook.MAPIFolder 
    Dim objLotusInboxItems As Outlook.Items 
    Dim objNameSpace As Outlook.NameSpace 
    Dim objMailProperty As Outlook.UserProperty 
    Dim objMailItem As Outlook.MailItem 
    Dim objParsedDate As Date 
    Dim sample As Object 

    Set olApp = CreateObject("Outlook.Application") 
    Set objNameSpace = olApp.GetNamespace("MAPI") 
    Set objLotusInbox = objNameSpace.GetDefaultFolder(olFolderInbox).Folders("Lotus Notes Inbox") 

    Set objLotusInboxItems = objLotusInbox.Items 

    For Each objMailItem In objLotusInboxItems 
     Set objMailProperty = objMailItem.UserProperties.Add("MyUserProp", olDateTime) 
     objParsedDate = CDate(Mid(objMailItem.Subject, (InStr(objMailItem.Subject, "[") + 1), (InStr(objMailItem.Subject, "]") - InStr(objMailItem.Subject, "[")) - 1)) 
     objMailProperty.Value = objParsedDate 
    Next 

    Set objLotusInboxItems = Nothing 
    Set objLotusInbox = Nothing 
    Set objNameSpace = Nothing 
    Set olApp = Nothing 

답변

1

나는 C# 및 Add-in-express VSTO addin을 사용하여 동일한 문제를 겪고있었습니다.

속성 변경 후 MailItem 개체를 저장하여 해결했습니다.

코드에서 나는 다음을 수행 할 것입니다 : 해당 지점에서 objMailItem.Save. 즉 For 루프의 각 반복 끝에.

NB : 내 C# 코드에서 할당 된 USerProperty 개체에 Marshal.ReleaseComObject를 사용합니다.

+0

나는 아직이 시도해야, 그래서 나는 그것이 실제로 작동합니까 확인할 수 있습니다, 이러한 노력을지나 이동했지만 내가 확인되면 답변으로 당신을 부여하고 싶습니다. –

1

VBA에서 이미 채우기 때문에 사용자 속성을 정렬 할 수있는 텍스트 필드로 변경할 수 있습니다.

내가 사용하는 방법은 규칙을 기반으로 스크립트를 실행하지만 귀하의 경우에는 for-each 루프에서 하위로 호출 할 수 있습니다.

Sub SomeAction(Item As Outlook.MailItem) 
    Dim myProperty As Outlook.UserProperty 

    Set myProperty = Item.UserProperties.Add("MyUserProp", olText, True) 
    myProperty.Value = Mid(objMailItem.Subject, (InStr(objMailItem.Subject, "[") + 1), (InStr(objMailItem.Subject, "]") - InStr(objMailItem.Subject, "[")) - 1)) 
    Item.Save 

    Set myProperty = Nothing 
End Sub 

남은 것은 텍스트 기반 사용자 정의 필드 인보기에 사용자 정의 열을 추가하는 것입니다. 당신이 날짜/시간 항목을 사용하고 있기 때문에 당신이 olDateTime

1

을 UserProperty를 정의 할 때

참고,이 방법은 내가하는 사용자 정의 열을 추가 위에서 답변을 결합했습니다 단지뿐만 아니라 작동합니다 스크립트를 선택하는 규칙을 실행하여 채워집니다. 그런 다음 발신자 도메인별로받은 편지함을 정렬 할 수 있습니다. 이전 기여자 들께 감사드립니다.

Public Sub SortByDomain(oMsg As Outlook.MailItem) 
    On Error Resume Next 

    Dim sDomain As String 'The Sender's domain 
    Dim oNS As Outlook.NameSpace 'My namespace 
    Dim oInbox As Outlook.MAPIFolder 'My Inbox 
    Dim oTarget As Outlook.MAPIFolder 'The domain folder 
    Dim myProperty As Outlook.UserProperty 


    'If it's not your domain, decipher the domain. 
    If InStr(oMsg.SenderEmailAddress, "mydomain.com") < 1 Then 
    sDomain = Mid(oMsg.SenderEmailAddress, InStr(oMsg.SenderEmailAddress, "@") + 1) 
    Else 
    sDomain = "mydomain.com" 
    End If 


    Set myProperty = oMsg.UserProperties.Add("SenderDomain", olText, True) 
     myProperty.Value = sDomain 
     oMsg.Save 

    'Cleanup. 
    Set oTarget = Nothing 
    Set oInbox = Nothing 
    Set oNS = Nothing 
    Set myProperty = Nothing 
    End Sub 
관련 문제