Articles: Customizing the Office Ribbon

Just came across the series of articles on Customizing Office Fluent Ribbons for Developers which covers all the customizing options that are available for Developers. Here are their links.

Hope this helps!

Getting Rules from an exchange account in Outlook

Getting Rules from an exchange account configured in Outlook is pretty easy though many developers who is working on it for the first time may confuse with the approach. I banged my head for 2 days to get the exact function and attributes to get them.

Dim olRules As Outlook.Rules = Globals.ThisAddIn.Application.Session.DefaultStore.GetRules

For Each olRule As Outlook.Rule In olRules
If olRule.Conditions.From.Recipients.Count > 0 Then
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.From.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim FromEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“FROM:  ” & FromEmail)
ElseIf olRule.Conditions.SentTo.Enabled Then
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.To.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim ToEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“TO: ” & ToEmail)
ElseIf olRule.Conditions.Subject.Enabled Then
MessageBox.Show(“Subject: ” & olRule.Conditions.Subject.Text)
End If
If olRule.Actions.Item(1).ActionType = Outlook.OlRuleActionType.olRuleActionMoveToFolder Then
MessageBox.Show(“Move To Folder: ” & olRule.Actions.MoveToFolder.Folder.FolderPath)
End If
Hope this Helps!

Common mistakes while installation and deployment of PIAs

Have you ever came across this error message while deploying PIAs along with your add-in as prerequisites?

Error 1316: Setup cannot read from file {PATH}PIARedist.MSI. Check your connection to the network, or CD-ROM drive. For other potential solutions, see SETUP.CHM.

This error occurs if the PIA’s already installed in the client system. This usually happens with Office 2007 if Outlook is installed with Contact Manager.
Business Contact Manager for Outlook 2007 installs the PIAs by default, and the file name is PIARedist.MSI.  However, the file from the Microsoft Download Center is called o2007pia.msi.  When you install the PIAs from the Microsoft Download Center, this name conflict causes the 1316 error.
The simplest solution is to just ignore the error, because this message means that the PIAs are already installed. If you want to correct the error, uninstall the PIAs through the list of installed programs for the specific computer. Then you can reinstall the PIAs with the Primary Interop Assemblies for the 2007 Microsoft Office system from the Microsoft Download Center.
For more details, refer to Misha’s article in her blog.

Developing add-ins for multiple versions of Office

Do you want to develop an add-in targeting multiple versions of Office? And you have basic questions like “Is it possible to do? ” and “How to do it?” ? Then you came to the right place. Few months back, I got a requirement to developed add-ins for Outlook 2003 and Outlook 2007. The functionality for both the versions is same. A doubt stroked… when the functionality is same, why would I develop two add-ins separately? Why don’t I make a single build for both the versions of Office?
Then I started searching for techniques to develop add-ins which works in both (2003 and 2007) and read many articles written by VSTO Experts in their blogs, Official VSTO Blog, MSDN, Forums and what not.
Misha Says:

Theoretically, you can develop an add-in for multiple versions of Microsoft Office by catering to the lowest common denominator. This means if you use an Excel 2003 add-in template in Visual Studio 2008, you would be able to develop and debug this with Excel 2007. However if you try this, you may meet these error messages: “You cannot debug or run this project, because the required version of the Microsoft Office application is not installed.”, followed by “Unable to start debugging.”

You can develop Office 2003 add-in in a system where Office 2007 is installed. The following is the procedure that demonstrates how to update your Visual Studio debugging options to use Microsoft Outlook 2007 to debug an add-in targeting Microsoft Outlook 2003.

  1. On the Project menu, click on ProjectName Properties
  2. Click on the Debug tab
  3. In the Start Action pane, click the Start external program radio button
  4. Click the file browser button and navigate to %ProgramFiles%Microsoft OfficeOffice12
  5. Choose Outlook.exe and click Open
  6. Press F5 to debug your add-in

For more details. Go through this article in Misha Shneerson’s Blog.
There are some tips and tricks to be followed and the things that one needs to take care while developing add-ins targeting multiple versions of Office in Andrew’s Blog. Have a look at this too. You might find it interesting and useful.
Here is an MSDN article on Running Solutions in Different Versions of Microsoft Office
Hope this helps!

How to get Sender Email Address from MailItem in Exchange Accounts?

For getting Sender Email of a MailItem in POP3/SMTP accounts if pretty easy. We can get that by olMailItem.SenderEmailAddress. But, for Exchange Accounts, its  a bit different. We need to get the AddressEntry first and then get the SMTP Address from that object. Here is a sample code that I framed for simpler understanding.

Dim objSender As Outlook.Recipient = Nothing
Dim objPropXR As Outlook.PropertyAccessor = Nothing
Dim strSMTPAddress As String = “”
Dim strSenderEntryID As String = “”
Dim objNS As Outlook.NameSpace = Nothing
Dim objAE As Outlook.AddressEntry = Nothing
Dim objEU As Outlook.ExchangeUser = Nothing

objNS = Globals.ThisAddIn.Application.GetNamespace(“MAPI”)
objPropXR = objMail.PropertyAccessor
strSenderEntryID = objPropXR.BinaryToString(objPropXR.GetProperty(“”))
objSender = objNS.GetRecipientFromID(strSenderEntryID)
objAE = objSender.AddressEntry
If objAE.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry Then
objEU = objAE.GetExchangeUser
strSMTPAddress = objEU.PrimarySmtpAddress
strSMTPAddress = objAE.Address
End If
MessageBox.Show (“Sender Email Address: ” & strSMTPAddress)

objMailItem is an object of Outlook.MailItem
Hope this helps!

How to get accounts from Outlook 2007?

Here is the sample code for getting Account Name and Email Address from Outlook 2007 using VSTO.
Dim olAccounts As Outlook.Accounts = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts
Dim acc As Outlook.Account
MessageBox.Show(“No. of accounts: ” & olAccounts.Count.ToString)
If olAccounts.Count > 0 Then
ReDim emails(olAccounts.Count)
For Each acc In olAccounts
MessageBox.Show(“Name: ” & acc.UserName & “Email: ” & acc.SmtpAddress)
MessageBox.Show(“There are no accounts in Outlook”)
End If

Hope this helps!