Using Excel Automation
A question came up recently about using the RiskAMP Add-in via Excel automation. When you launch Excel from another application - an Access form, for example - add-ins aren’t loaded automatically. This means that RiskAMP functions won’t work in a spreadsheet.
The same problem exists with all add-ins, and it’s just a function of how Excel works. There’s a way to solve it, but it’s sometimes a bit hard to figure out (it doesn’t help that it doesn’t make much sense).
Here’s an example of VB code that opens Excel and then activates all the add-ins. Add a project reference to the Microsoft Excel library, then use this function:
Private Sub Start_Excel() Dim xlAddIn As Excel.AddIn Dim xlApp As New Excel.Application xlApp.Application.Visible = True ' for this method to work, a workbook must be ' loaded with Open or Add xlApp.Workbooks.Add() ' loop over all the Add-ins that are set to ' "installed", and toggle the flag from True ' to False and back again. For Each xlAddIn In xlApp.AddIns If xlAddIn.Installed Then xlAddIn.Installed = False xlAddIn.Installed = True End If Next xlAddIn End Sub
For this method to work, the RiskAMP Add-in must be already installed, and “checked” in the Excel add-ins menu. But basically, if the Add-in is loaded when you start Excel normally, this code should work to start it via automation.