#Requires -Version 5.1 <# JbTecWiz Support Centre -- generated fix script Fault : An add-in keeps disabling itself, or will not stay enabled Fix : Check what the add-in is registered to do Source: https://jbtecwiz.com/support/win-office-addin-disabled Run as : PowerShell as administrator Expect : 20 minutes Risk : low Reversible : yes WHEN THIS IS THE RIGHT FIX The add-in is missing entirely with no message. HOW TO UNDO IT Set LoadBehavior back to its previous value. This script walks the fix one step at a time and asks before each one. Steps with no command are things you do yourself -- it prints those and waits. Run with -DryRun to print without executing. #> [CmdletBinding()] param( # Print every step and command without running anything. [switch]$DryRun, # Do not ask before each step. Read the script first if you use this. [switch]$Unattended ) $ErrorActionPreference = 'Stop' $script:Failed = 0 # - THIS SCRIPT WILL NOT RUN UNTIL YOU EDIT IT - # The commands below contain values only you can supply. Search the # script for each one, replace it, then delete this block. $script:MustEdit = @( 'Vendor.AddinName' # a placeholder add-in ProgID ) if ($script:MustEdit.Count) { Write-Host "" Write-Host ' This script needs editing before it can run.' -ForegroundColor Yellow Write-Host ' Replace each of these with a real value:' -ForegroundColor Yellow $script:MustEdit | ForEach-Object { Write-Host (" " + $_) -ForegroundColor Yellow } Write-Host "" Write-Host ' Then delete the $script:MustEdit block near the top.' Write-Host "" exit 2 } # This fix is documented as needing an elevated session. $id = [Security.Principal.WindowsIdentity]::GetCurrent() if (-not (New-Object Security.Principal.WindowsPrincipal $id).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host '' Write-Host ' This fix needs an elevated PowerShell.' -ForegroundColor Yellow Write-Host ' Close this window, right-click PowerShell, Run as administrator,' Write-Host ' and run the script again.' Write-Host '' exit 3 } function Write-Rule { param([string]$Text) Write-Host '' Write-Host ('-' * 70) -ForegroundColor DarkGray if ($Text) { Write-Host $Text -ForegroundColor Cyan } } function Show-Prose { param([string]$Text, [string]$Colour = "Gray") if (-not $Text) { return } $words = $Text -split "\s+"; $line = " " foreach ($w in $words) { if (($line.Length + $w.Length) -gt 74) { Write-Host $line -ForegroundColor $Colour; $line = " " } $line += "$w " } if ($line.Trim()) { Write-Host $line -ForegroundColor $Colour } } function Invoke-Step { param( [int]$Number, [string]$Do, [string]$Why, [scriptblock]$Command, [switch]$Manual, [string]$Shell = "powershell" ) Write-Rule " Step $Number of 4" Show-Prose $Do "White" if ($Why) { Write-Host ""; Show-Prose $Why "DarkGray" } if ($Manual) { Write-Host '' Write-Host ' -> Do this yourself, then press Enter to carry on.' -ForegroundColor Yellow if (-not $Unattended -and -not $DryRun) { [void](Read-Host) } return } Write-Host '' foreach ($l in ($Command.ToString().Trim() -split "`n")) { Write-Host (" " + $l.Trim()) -ForegroundColor Green } Write-Host '' if ($DryRun) { Write-Host " (dry run -- not executed)" -ForegroundColor DarkGray; return } if (-not $Unattended) { $a = Read-Host " Run this step? [Y]es / [S]kip / [Q]uit" if ($a -match "^[Qq]") { Write-Host " Stopped at your request."; exit 0 } if ($a -match "^[Ss]") { Write-Host " Skipped." -ForegroundColor DarkGray; return } } try { & $Command } catch { $script:Failed++ Write-Host (" Step $Number failed: " + $_.Exception.Message) -ForegroundColor Red Show-Prose "The rest of the fix may depend on this. Read the write-up before carrying on." "Red" if (-not $Unattended) { $c = Read-Host " Carry on anyway? [y/N]" if ($c -notmatch "^[Yy]") { exit 1 } } } } Write-Rule Write-Host ' An add-in keeps disabling itself, or will not stay enabled' -ForegroundColor White Write-Host ' Check what the add-in is registered to do' -ForegroundColor Cyan Write-Host '' Write-Host ' Risk: low Reversible 20 minutes' Write-Rule if (-not $Unattended -and -not $DryRun) { $go = Read-Host ' Ready? [y/N]' if ($go -notmatch "^[Yy]") { Write-Host " Nothing was changed."; exit 0 } } Invoke-Step -Number 1 -Do 'List every registered add-in and its LoadBehavior, from both hives.' -Why '3 means load at startup, which is what you want. 2 means it failed and was turned off. 0 means disabled. 8 or 9 relate to load-on-demand. The WOW6432Node hive matters because a 32-bit add-in on 64-bit Office registers there and is invisible if you only look at the main key.' -Command { foreach ($h in 'HKCU:\Software\Microsoft\Office\Excel\Addins','HKLM:\SOFTWARE\Microsoft\Office\Excel\Addins','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\Excel\Addins') { Get-ChildItem $h -ErrorAction SilentlyContinue | ForEach-Object { [pscustomobject]@{ Hive=$h; Addin=$_.PSChildName; LoadBehavior=(Get-ItemProperty $_.PSPath).LoadBehavior } } } } Invoke-Step -Number 2 -Do 'Set it back to load at startup.' -Command { Set-ItemProperty 'HKCU:\Software\Microsoft\Office\Excel\Addins\Vendor.AddinName' -Name LoadBehavior -Type DWord -Value 3 } Invoke-Step -Number 3 -Do 'Confirm the add-in''s architecture matches Office. A 32-bit COM add-in will not load into 64-bit Office at all, and this produces exactly the silent absence being reported.' -Command { Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration' | Select-Object Platform } Invoke-Step -Number 4 -Do 'If the architectures do not match, the add-in has to be replaced with the matching build -- there is no client-side setting that bridges this.' -Manual Write-Rule " Confirm it worked" Show-Prose 'LoadBehavior reads 3 after a restart of the application, and the add-in appears on the ribbon.' 'White' Write-Rule if ($script:Failed -gt 0) { Write-Host (" Finished with " + $script:Failed + " failed step(s).") -ForegroundColor Yellow Show-Prose 'Read the full write-up at https://jbtecwiz.com/support/win-office-addin-disabled' 'Yellow' } else { Write-Host ' Finished.' -ForegroundColor Green } Write-Host '' Show-Prose 'To undo: Set LoadBehavior back to its previous value.' 'DarkGray' Write-Rule