Trying to run excel xlam add-in to run and load
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"}
$Excel.Quit()
}
Answers (3)
$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 ...
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.