Share via


Create a Marketing Campaign

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

C#

  private void CreateMarketingCampaign()
        {
            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 mktgCampFolder = (Outlook.Folder)bcmRootFolder.Folders["Marketing Campaigns"];
            Outlook.UserProperty userProp;

            Outlook.TaskItem taskItem = (Outlook.TaskItem)mktgCampFolder.Items.Add("IPM.Task.BCM.Campaign");
            taskItem.Subject = "New Marketing Campaign";

            if (taskItem.UserProperties["Campaign Code"] == null)
            {
                userProp = taskItem.UserProperties.Add("Campaign Code", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "SP2";
            }

            if (taskItem.UserProperties["Campaign Type"] == null)
            {
                userProp = taskItem.UserProperties.Add("Campaign Type", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "Direct Mail Print";
            }

            if (taskItem.UserProperties["Budgeted Cost"] == null)
            {
                userProp = taskItem.UserProperties.Add("Budgeted Cost", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olCurrency, false, false);
                userProp.Value = 243456;
            }

            if (taskItem.UserProperties["Delivery Method"] == null)
            {
                userProp = taskItem.UserProperties.Add("Delivery Method", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = "Word Mail Merge";
            }

            taskItem.StartDate = System.DateTime.Parse("4/20/2006");
            taskItem.DueDate = System.DateTime.Parse("5/20/2006");

            taskItem.Save();

        }


VBA

  Sub CreateMarketingCampaign()

   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 newMarketingCampaign 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 newMarketingCampaign = bcmCampaignsFldr.Items.Add("IPM.Task.BCM.Campaign")
   newMarketingCampaign.Subject = "Sales Project with Wide World Importers"
   
   If (newMarketingCampaign.UserProperties("Campaign Code") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("Campaign Code", olText, False, False)
        userProp.Value = "SP2"
   End If
   
   If (newMarketingCampaign.UserProperties("Campaign Type") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("Campaign Type", olText, False, False)
        userProp.Value = "Direct Mail Print"
   End If
   
   If (newMarketingCampaign.UserProperties("Budgeted Cost") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("Budgeted Cost", olCurrency, False, False)
        userProp.Value = 243456
   End If

   If (newMarketingCampaign.UserProperties("Delivery Method") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("Delivery Method", olText, False, False)
        userProp.Value = "Word Mail Merge"
   End If

   If (newMarketingCampaign.UserProperties("End Time") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("End Time", olDateTime, False, False)
        userProp.Value = "3/10/2006"
   End If
   
   If (newMarketingCampaign.UserProperties("Start Time") Is Nothing) Then
        Set userProp = newMarketingCampaign.UserProperties.Add("Start Time", olDateTime, False, False)
        userProp.Value = "3/9/2006"
   End If
   
   newMarketingCampaign.Save

   Set newMarketingCampaign = Nothing
   Set bcmCampaignsFldr = Nothing
   Set bcmRootFolder = Nothing
   Set olFolders = Nothing
   Set objNS = Nothing
   Set olApp = Nothing
End Sub


See Also

Select a Marketing Campaign | Edit a Marketing Campaign | Delete a Marketing Campaign | Print Total Accounts | Print Total Business Contacts | Print Total Opportunities | Print Total Leads | 2007 Office System: Updated Developer Content