Change the value of a user-defined field with VBA

Posted on 2012-09-15
Last Modified: 2013-03-12
Hi all,

I'm quite new to programming VBA in Outlook so sorry if this a basic question.

I created a custom field for tasks "setpriority". The type of this field is "text".
Now I would like to change the value of this field with a VBA script to a value like "A", so that i can add this script to the Ribbon.

The VBA script should change the value of the task selected in the task overview or alternatively of the task that is open at the moment.

I searched for code examples that do that but i didn't find it and i am not shure which function i need to use do this.

Can you please point me to the right functions to use or give some code examples ?


This example is similar to what i want to do but it is for messages not for tasks
Question by:Pantarai
    1 Comment

    Accepted Solution

    In the meantime I was able to realise this function:
    If anybody has the same problem
    Public Sub A()
      Dim Task As Outlook.TaskItem
      Dim Selection As Outlook.Selection
      Dim Folder As Outlook.MAPIFolder
      Dim i&
      Dim objProperty As Outlook.UserProperty
      Dim UserDefinedFieldName As String
      UserDefinedFieldName = "Prioritäten"
      Set Folder = ActiveExplorer.CurrentFolder
      If Folder.DefaultItemType = olTaskItem Then
        Set Selection = ActiveExplorer.Selection
        If Selection.Count > 0 Then
          For i = 1 To Selection.Count
            Set Task = Selection(i)
            Set objProperty = Task.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olText)
                        objProperty.Value = "A"
        End If
      End If
    End Sub

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    My experience with Windows 10 over a one year period and suggestions for smooth operation
    Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now