Home → Techniques and Tips → VBA Programming with @RISK → Shutting Down @RISK from VBA Code
Applies to: @RISK for Excel 5.x–7.x, Professional and Industrial Editions
(@RISK Standard cannot be automated with VBA macros.)
I have written an application using VBA to control @RISK. How can I unload @RISK from within my Visual Basic?
The base method is Risk.UnloadAddIn. However, there are some differences between @RISK 5 and later @RISK in how you use this method.
In @RISK 6.x/7.x:
In the Visual Basic Editor, click Tools » References and select Palisade @RISK n.n for Excel Object Library, whichever one appears. Don't select Risk.xla, as you normally would when automating @RISK 6. Shutting down @RISK includes closing Risk.xla, but that's impossible if it's checked in Tools » References.
All the class definitions are in the @RISK n.n for Excel Object Library. The only thing VBA gets from Risk.xla is the object called Risk. So you just create that object (actually a function) yourself, using a technique called demand loading.
Here's some sample code:
Dim Risk As AtRiskOL6.Risk
Set Risk = Application.Run("Risk.xla!Risk")
...
Risk.UnloadAddin
After calling the UnloadAddIn method, you must immediately return control to Excel (Return statement or end of macro). The unload process is asynchronous.
For a fuller explanation of demand loading, please open @RISK Help » Developer Kit (XDK) » Automation Guide and see "Demand-Loading @RISK", near the end of the PDF. (The Automation Guide is available in @RISK 6.2 and later.)
In @RISK 5.x:
In the Visual Basic Editor, click Tools » References and select Palisade @RISK 5.0 for Excel Object Library, Palisade @RISK 5.5 for Excel Object Library, or Palisade @RISK 5.7 for Excel Object Library, whichever one appears.
Use the
Risk.UnloadAddin
method, and then immediately return control to Excel (Return statement or end of macro). The unload process is asynchronous.
Can I unload @RISK synchronously?
Instead of unloading @RISK, you can hide its tab of the ribbon (in Excel 2007 and later) or its toolbars and menu (in earlier Excels). Use
Risk.InterfaceHidden = True
That leaves @RISK loaded but invisible. You can turn the interface back on by setting that property to False. When you start @RISK, the interface is always visible, regardless of any previous setting of the Risk.InterfaceHidden property.
See also: Launching @RISK from a Visual Basic Macro in Excel.
Last edited: 2015-08-31