I have a problem in adding value to a custom field created in outlook2003. I
can able to create a custom field in outlook inbox, but i'm not able to add
value to it. To my knowledge the code seems to be fine and the value is
assigned to the custom field but something is blocking to display it.
Herewith i've pasted my code for your reference.
Dim olNamespace As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Set olNamespace = Outlook.Application.GetNamespace("MAPI")
Set cf = olNamespace.GetDefaultFolder(olFolderInbox)
Dim emailitem As Outlook.MailItem
For Each emailitem In cf.Items
Dim prop As Outlook.UserProperty
Set prop = emailitem.UserProperties.Add("HowOld", olText, False, Nothing)
prop.Value = DateDiff("d", emailitem.ReceivedTime, Now) & " days."
emailitem.Save
set prop = nothing
Next
Note: I'm using vb 6.0
Value is not getting displayed. Whereas i tried to display the column value
using "MsgBox emailitem.ItemProperties("HowOld")". i'm getting the message
box with value
I created a custom view using the below code
==========================================
Sub AddColumnToView(ByVal strName As String, ByVal strHead As String, _
ByVal strProp As String)
'Creates a new Table view and adds a column.
Dim objView As View
Dim objViews As Views
'Set a reference to the MSXML parser.
Dim objXMLDoc As New MSXML2.DOMDocument
'Dim objNode As MSXML2.IXMLDOMNode
Dim objRoot As MSXML2.IXMLDOMNode
On Error GoTo AddColumnToView_Err
Set objViews = _
Application.GetNamespace(Type:="MAPI").GetDefaultFolder(FolderType:=olFolderInbox).Views
'Set objView = objViews.Add(Name:=strName, ViewType:=olTableView, _
' SaveOption:=olViewSaveOptionAllFoldersOfType)
Set objView = objViews.Add(Name:=strName, ViewType:=olTableView, _
SaveOption:=olViewSaveOptionThisFolderEveryone)
'Load the XML schema into the parser.
objXMLDoc.loadXML bstrXML:=objView.XML
'Create a reference to the root element.
Set objRoot = objXMLDoc.documentElement
'Walk the tree to obtain a column node.
With objRoot.insertBefore(newChild:=objXMLDoc.createElement("column"), _
refChild:=objRoot.selectNodes(querystring:=("column")).Item(Index:=5))
'Add properties to the new column.
..appendChild(newChild:=objXMLDoc.createElement(tagName:="Heading")).Text =
strHead
..appendChild(newChild:=objXMLDoc.createElement(tagName:="prop")).Text =
strProp
'.appendChild(newChild:=objXMLDoc.createElement(tagName:="sort")).Text =
"desc"
..appendChild(newChild:=objXMLDoc.createElement(tagName:="width")).Text = 50
..appendChild(newChild:=objXMLDoc.createElement(tagName:="type")).Text =
"string"
'.appendChild(newChild:=objXMLDoc.createElement(tagName:="type")).Text = "i4"
End With
'Copy the schema from the parser to the View object.
objView.XML = objXMLDoc.XML
'Save the schema.
objView.Save
'Apply the changes to the view.
objView.Apply
AddColumnToView_End:
Set objXMLDoc = Nothing
Exit Sub
AddColumnToView_Err:
MsgBox "Error Source: " & Err.Source & " ::Error Number: " &
Str$(Err.Number) & " ::Error Desc: " & Err.Description & " " & strProp
Resume AddColumnToView_End
End Sub
==========================================
I called the above method using
Call AddColumnToView(strName:="New Table View2", strHead:="HowOld", _
strProp:="urn: schemas: mailheader: original
-Recipient")
Eric Legault said:
Try running this macro on the current folder:
Sub AppendCategoriesToSubjectLine()
Dim objItems As Outlook.Items
Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem, objItem As Object
Set objFolder = ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
For Each objItem In objItems
If objItem.Class = olMail Then
Set objMail = objItem
If objMail.Categories <> "" Then
objMail.Subject = objMail.Subject & " [" &
objMail.Categories & "]"
objMail.Save
End If
End If
Set objMail = Nothing
Next
Set objItem = Nothing
Set objItems = Nothing
Set objMail = Nothing
Set objFolder = Nothing
End Sub
--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog:
http://blogs.officezealot.com/legault/
DB01 said:
....hope this is not a double post....
I'm stumped. I use Google desktop search and most of you know that it
does not search outlook categories. So I had an idea, check all mail
in all folders (including personal folders) and modify the subject by
adding to it the list of categories. So, for example, if the subject
were "planning meeting notes" and the categories were "planning",
"notes", "projectx", "customerz", I'd like the new subject line to read
"planning meeting notes [lplanning lnotes lprojectx lcustomerz]" I
started writing the code, but quickly became overwhelmed. Is there
someone on the list who has done something like this before (or
something close) so that I may borrow your code? Much appreciated!
DB01