It is possible to solve this without a custom action, although this solution may end up quite verbose if you want to support a lot of different versions of office. The general idea is to use a <RegistrySearch.../>
to set a property to the location of a particular version of office. Then use that property as both a directory location and a condition for a component.
One slight complication: The property used as the Directory attribute of the Directory element should be a copy of the property found by registry search. If we try and use the same property returned by the registry search, the Directory element will set the property to the resolved directory location, which will set the condition to true and install the component anyway.
The <RegistrySearch.../>
for Excel 2010:
<!-- Search for Excel 2010 -->
<Property Id="OFFICE14LOCATION">
<RegistrySearch Id="Office14Location"
Root="HKLM"
Key="SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot"
Name="Path"
Type="raw"/>
</Property>
<!-- Make a copy of the property for the directory reference -->
<SetProperty Id="Office14DirectoryPath" Value="[OFFICE14LOCATION]" Before="CostFinalize"/>
The component part for Excel 2010:
<!-- Conditionally install MyAddIn.xll to the Office14\Library directory
Remember to reference Office14Library in a <Feature> -->
<DirectoryRef Id="Office14Library">
<Component Id="Office14AddIn" Guid="-- your GUID --">
<Condition>OFFICE14LOCATION</Condition>
<File Id="Office14AddIn" Name="MyAddIn.xll" Source="MyAddIn.xll" />
</Component>
</DirectoryRef>
The directory part for Excel 2010:
<!-- Note: Include this as a child of <Directory Id="TARGETDIR" ..> -->
<Directory Id="Office14DirectoryPath" Name="Office14"> <!-- Note: The Name attribute is redundant but needed to avoid ICE30 warning -->
<Directory Id="Office14Library" Name="Library"/>
</Directory>
You will need to repeat the above blocks for each version of office supported.
Excel 2007
To support Excel 2007 you would change the references to 14 in the above example to 12. For example:
<!-- Search for Excel 2007-->
<Property Id="OFFICE12LOCATION">
<RegistrySearch Id="Office12Location"
Root="HKLM"
Key="SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot"
Name="Path"
Type="raw"/>
</Property>
<!-- Make a copy of the property for the directory reference -->
<SetProperty Id="Office12DirectoryPath" Value="[OFFICE12LOCATION]" Before="CostFinalize"/>
<!-- Conditionally install MyAddIn.xll to the Office12\Library directory
Remember to reference Office12Library in a <Feature> -->
<DirectoryRef Id="Office12Library">
<Component Id="Office12AddIn" Guid="-- your GUID --">
<Condition>OFFICE12LOCATION</Condition>
<File Id="Office12AddIn" Name="MyAddIn.xll" Source="MyAddIn.xll" />
</Component>
</DirectoryRef>
<!-- Note: Include this as a child of <Directory Id="TARGETDIR" ..> -->
<Directory Id="Office12DirectoryPath" Name="Office12"> <!-- Note: The Name attribute is redundant but needed to avoid ICE30 warning -->
<Directory Id="Office12Library" Name="Library"/>
</Directory>
64 Bit Excel 2010
The solution can also be extended to support the 64 bit version of Excel 2010:
The <RegistrySearch.../>
for 64 bit Excel 2010:
<!-- Search for 64 bit Excel 2010 -->
<Property Id="OFFICE14LOCATIONX64">
<RegistrySearch Id="Office14LocationX64"
Root="HKLM"
Key="SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot"
Name="Path"
Win64="yes"
Type="raw"/>
</Property>
<!-- Make a copy of the property for the directory reference -->
<SetProperty Id="Office14DirectoryPathX64" Value="[OFFICE14LOCATIONX64]" Before="CostFinalize"/>
The component part for 64 bit Excel 2010:
<!-- Conditionally install MyAddIn.xll to the Office14\Library directory
Remember to reference Office14Library in a <Feature> -->
<DirectoryRef Id="Office14LibraryX64">
<Component Id="Office14AddInX64" Win64="yes" Guid="-- your GUID --">
<Condition>OFFICE14LOCATIONX64</Condition>
<File Id="Office14AddInX64" Name="MyAddIn.xll" Source="MyAddIn.xll" />
</Component>
</DirectoryRef>
The directory part for 64 bit Excel 2010:
<!-- Note: Include this as a child of <Directory Id="TARGETDIR" ..> -->
<Directory Id="Office14DirectoryPathX64" Name="Office14X64"> <!-- Note: The Name attribute is redundant but needed to avoid ICE30 warning -->
<Directory Id="Office14LibraryX64" Name="Library"/>
</Directory>
Useful references:
How to detect installed version of MS-Office?
How do you copy a set of files to multiple places using Wix?