Scripting Question

Trying to run excel xlam add-in to run and load

11/09/2015 3909 views

Hi Guys

I have the following script that I've put together.

I need to load a xlam add-in into the current logged on user. Unfortunately we have both 32 and 64 bit OS machines. So the installation directory that holds the xlam add-in can be in either C:\Program Files\<program> or C:\Program Files (x86)\<program> depending on the os architecture.

The script I have below seems to work on 32bit OS and doesn't load on x64 OS, I can't see any error messages either. Essentially the add-in doesn't load, any help would be greatly appreciated.

$Addinfilename = 'AdvanceOffice.xlam'
$Addinfilepath = 'C:\Program Files\Datastream\Datastream Advance\'
$Addinfilepath64 = 'C:\Program Files (x86)\Datastream\Datastream Advance\'
$Excel = New-Object -ComObject excel.application
$ExcelWorkbook = $excel.Workbooks.Add()
$os_type = (Get-WmiObject -Class Win32_ComputerSystem).SystemType -match '(x86)'

if ($os_type -eq "True") {
        $ExcelWorkbook.Application.AddIns | Where-Object {$_.name -eq $Addinfilename} -eq $null
        $ExcelAddin = $ExcelWorkbook.Application.AddIns.Add("$Addinfilepath$Addinfilename", $True)
        $ExcelAddin.Installed = "True"
        Write-Host "$Addinfilename added"        
        Write-host "32 bit Windows OS"
        Write-Host $os_type
 Else {
    ($os_type -NotLike "True")
    $ExcelWorkbook.Application.AddIns | Where-Object {$_.name -eq $Addinfilename} -eq $null  
    $ExcelAddin = $ExcelWorkbook.Application.AddIns.Add("$Addinfilepathx64$Addinfilename", $True)
    $ExcelAddin.Installed = "True"
    Write-Host "$Addinfilename added"}

0 Comments   [ + ] Show comments


Community Chosen Answer

Just to clarify, you have ensured the addin works for 64-bit Office? I say this because its recommended that ppls used 32-bit Office due to compatibility issues with plugins, ppl that move to 64-bit Office normally want to exceed the 2GB(?) limit in Excel etc - think Powerpivot and all those fancy forecasting stuff that sales and finance use.

*update: you cant debug...
$Addinfilepath64 = 'C:\Program Files (x86)\Datastream\Datastream Advance\'
$ExcelAddin = $ExcelWorkbook.Application.AddIns.Add("$Addinfilepathx64$Addinfilename", $True)

Missing the x ...

Also you're missing a terminating curly bracket at the Write-Host $os_type at the first IF block ...

Answered 11/09/2015 by: rileyz
Red Belt

All Answers

The add-in only runs on 32 bit office. The application is 32bit, but the location of where the add-in is located will change depending on the os architecture, eg. Program Files or Program Files (x86).

All i'm trying to do is determine the os architecture for the machine and load the corresponding add-in based on the location of where it lives.
Answered 11/09/2015 by: djjass
Senior Purple Belt

  • Ah! I cant read, lol.
    • Read my updated post.
Surely a 32-bit app should be installed in the 32-bit file location, irrespective of the host OS's bitness?
Answered 11/09/2015 by: VBScab
Red Belt

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ