Share via


Edit a Marketing Campaign

Outlook Developer Reference
Edit a Marketing Campaign

The Marketing Campaign object records the life cycle of a marketing effort. Data collected from a Marketing Campaign can contribute by generating new business leads, building brands, and improving customer satisfaction.

To edit a Marketing Campaign programmatically, do the following:

  1. Select the object.
  2. Assign new values to those properties that you want to edit.
  3. Invoke the Save method on the object to save the changes.

The following C# and Visual Basic for Applications (VBA) examples show how to edit a Marketing Campaign object.

  private void EditMarketingCampaign()
        {
            Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
            Outlook.Application olApp = (Outlook.Application)_app;
            Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
            Outlook.Folders folders = olNameSpace.Session.Folders;
            Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"];
            Outlook.Folder campaignsFolder = (Outlook.Folder)bcmRootFolder.Folders["Marketing Campaigns"];
        string strQuery = "[Subject] = 'New Marketing Campaign'";

        Outlook.TaskItem campaignItem = (Outlook.TaskItem)campaignsFolder.Items.Find(strQuery);
        if (campaignItem != null)
        {
            if (campaignItem.UserProperties["Budgeted Cost"] == null)
            {
                Outlook.UserProperty userProp = campaignItem.UserProperties.Add("Budgeted Cost", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olCurrency, false, false);
                userProp.Value = 33333;
            }
            else
            {
                campaignItem.UserProperties["Budgeted Cost"].Value = 33333;
            }
            campaignItem.Save();
        }

        else
        {
            Console.WriteLine("Campaign Not Found");
        }

    } 
  Sub UpdateMarketingCampaign()

Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmRootFolder As Outlook.Folder Dim bcmCampaignsFldr As Outlook.Folder Dim existMarketingCampaign As Outlook.TaskItem Dim userProp As Outlook.UserProperty

Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders

Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmCampaignsFldr = bcmRootFolder.Folders("Marketing Campaigns")

Set existMarketingCampaign = bcmCampaignsFldr.Items.Find("[Subject] = 'Sales Project with Wide World Importers'") If Not TypeName(existMarketingCampaign) = "Nothing" Then

  If (existMarketingCampaign.UserProperties("Budgeted Cost") Is Nothing) Then
    Set userProp = existMarketingCampaign.UserProperties.Add("Budgeted Cost", olCurrency, False, False)
    userProp.Value = 55555
  Else
    existMarketingCampaign.UserProperties("Budgeted Cost").Value = 55555
  End If

  existMarketingCampaign.Save

Else

  MsgBox ("Marketing Campaign not found")

End If

Set existMarketingCampaign = Nothing Set bcmCampaignsFldr = Nothing Set bcmRootFolder = Nothing Set olFolders = Nothing Set objNS = Nothing Set olApp = Nothing

End Sub

See Also

Create a Marketing Campaign | Select a Marketing Campaign | Delete a Marketing Campaign | Office Developer Center: Outlook 2007