locked
Outlook: Add text to Appointment? RRS feed

  • Question

  • I have a custom button which I have added to a ribbon. The ribbon is set to type "Microsoft.Outlook.Appointment" so it shows when I create a new appointment. What I would like to do is be able to click the button and it would insert text at the end of the appointment body.

    Can anyone help me out with this?

    Friday, July 30, 2010 10:02 PM

Answers

  • Hope this helps

    VB.NET

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
        Dim item As Outlook.AppointmentItem = TryCast(Globals.ThisAddIn.Application.ActiveInspector.CurrentItem, Outlook.AppointmentItem)
        If item IsNot Nothing Then
          item.Body &= vbCrLf & "Insert custom text"
        End If
        item.Body &= "My text"
      End Sub
    
    C#
    private void Button1_Click(System.Object sender, Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e)
    {
    	Outlook.AppointmentItem item = Globals.ThisAddIn.Application.ActiveInspector.CurrentItem as Outlook.AppointmentItem;
    	if (item != null) {
    		item.Body += Constants.vbCrLf + "Insert custom text";
    	}
    	item.Body += "My text";
    }
    
    Saturday, July 31, 2010 2:57 AM

All replies

  • Hope this helps

    VB.NET

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
        Dim item As Outlook.AppointmentItem = TryCast(Globals.ThisAddIn.Application.ActiveInspector.CurrentItem, Outlook.AppointmentItem)
        If item IsNot Nothing Then
          item.Body &= vbCrLf & "Insert custom text"
        End If
        item.Body &= "My text"
      End Sub
    
    C#
    private void Button1_Click(System.Object sender, Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e)
    {
    	Outlook.AppointmentItem item = Globals.ThisAddIn.Application.ActiveInspector.CurrentItem as Outlook.AppointmentItem;
    	if (item != null) {
    		item.Body += Constants.vbCrLf + "Insert custom text";
    	}
    	item.Body += "My text";
    }
    
    Saturday, July 31, 2010 2:57 AM
  • Thanks, that works perfectly. Could the explain the purpose of if(item!=null) and the code?
    Sunday, August 1, 2010 5:18 PM
  • I just re-read my previous post and it doesn't read well. Let me try again.

    What does

    item.Body += Constants.vbCrLf + "Insert custom text";"

    do?

    Monday, August 2, 2010 7:46 AM