Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

vba - Set custom value when item moved to folder in outlook

I'm looking to set a Date on a field anytime an email is moved into a specific folder. the field is custom called "Completed Date". Could I get a little help on VBA code to set a custom field (date) when an item is moved into a folder (folder name is "Completed").

I'm ultimately looking to report on the time an item (custom form email) was received to the time it was completed (as per the action of moving the email to a completed folder.

Very rudimentary ticketing system, I'm very aware :) .

thanks,

A

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use ItemAdd http://www.outlookcode.com/article.aspx?id=62 where you reference the "Completed" folder.

Combine it with code like this http://www.vbaexpress.com/forum/showthread.php?5738-Need-to-Add-a-Userdefined-Property-to-Mail-Items

SAMPLE CODE

Change it so you do not update all items in the folder just the one item that triggered ItemAdd.

Option Explicit 

Sub AddAUserDefinedProperty() 

Dim olApplication   As Outlook.Application 
Dim olNameSpace     As Outlook.NameSpace 
Dim olFolder        As Outlook.MAPIFolder 
Dim olItem          As Object 
Dim strDomain       As String 
Dim olProperty      As Outlook.UserProperty 

Set olApplication = New Outlook.Application 
Set olNameSpace = olApplication.GetNamespace("Mapi") 
Set olFolder = olNameSpace.GetDefaultFolder(olFolderJunk) 

For Each olItem In olFolder.Items 

    strDomain = Mid(olItem.SenderEmailAddress, _ 
    InStr(1, olItem.SenderEmailAddress, "@") + 1) 

    Set olProperty = olItem.UserProperties.Add("Domain", olText) 

    olProperty.Value = strDomain 

    Debug.Print olItem.SenderEmailAddress, olProperty.Value 

    olItem.Save 

Next olItem 

Set olApplication = Nothing 
Set olNameSpace = Nothing 
Set olFolder = Nothing 
Set olProperty = Nothing 

End Sub 

Even more reference material here http://www.codeproject.com/Articles/427913/Using-User-Defined-Fields-in-Outlook


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...