Using a 32bit COM object in a 64bit environment

.net, 64-bit, excel, ms-office, powershell

Solution

You need to load the Excel interop assembly like so:

Add-Type -AssemblyName Microsoft.Office.Interop.Excel

If you need to use types defined in the Excel interop assembly, you have to load that assembly into PowerShell before you can reference types defined in it. You're using an enumeration (xlFileFormat) so PowerShell needs the definition of that type.

Problem

I'm using powershell 3 on Win7/64bit . I am trying to use .net of excel (32bit) with this command : [microsoft.office.interop.excel.xlfileformat] And I got this error: unable to find type microsoft.office.interop.excel.xlfileformat: make sure that the assembly containing this type is loaded. I didn't have this error before when I used Win7/32bit. Maybe someone know how to fix that?

Original source