Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1826
  • Last Modified:

Change the value of a user-defined field with VBA

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 ?

Thanks

Regards,
Matthias
EDIT:
This example is similar to what i want to do but it is for messages not for tasks
http://www.codeproject.com/Articles/427913/Using-User-Defined-Fields-in-Outlook
0
Pantarai
Asked:
Pantarai
1 Solution
 
PantaraiAuthor Commented:
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"
        Task.Save
      Next
    End If
  End If
End Sub

Open in new window

0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now