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?
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.
Had a bit of a similar problem when trying to run the Redemption.dll in PowerShell 64 bit for Outlook 2010 32 bit. This is how I solved it:
regsvr32.exe 'C:\path\Redemption.dll'
regsvr32.exe 'C:\path\Redemption64.dll'
$Job = Start-Job -ScriptBlock {
$routlook = New-Object -COM Redemption.RDOSession
$routlook
} -RunAs32
Wait-Job -Job $Job
Receive-Job -Job $Job
Apparently Start-Job has a switch to run a ScriptBlock in 32 bit mode. This works just great for what I need it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With