Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a 32bit COM object in a 64bit environment

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?

like image 365
Doron Avatar asked Oct 24 '25 15:10

Doron


2 Answers

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.

like image 176
Keith Hill Avatar answered Oct 27 '25 09:10

Keith Hill


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!

like image 40
DarkLite1 Avatar answered Oct 27 '25 09:10

DarkLite1