Palisade Knowledge Base

HomeTechniques and TipsVBA Programming with @RISKWhich Version of @RISK Is Running?

10.15. Which Version of @RISK Is Running?

Applies to: @RISK 4.x–7.x

Can I use Visual Basic code to determine which version of @RISK is running?

Here is a VBA function from our developers:

'Determine the version number of the running copy of @RISK.
'If @RISK 5.x–7.x is running, the exact version number is returned.
'If @RISK 4.x is running, the string '4.x' is returned.
'If no copy of @RISK 4.x–7.x is running, a blank string is returned.

Public Function GetAtRiskVersion() As String
   Dim rc As String
   Dim addinWorkbook As Workbook
   Dim dummyValue As Long

   'Make sure the Risk.xla add-in workbook is open.  If it isn't, @RISK 4.x–7.x
   'isn't loaded:

   On Error Resume Next
   Set addinWorkbook = Application.Workbooks("Risk.xla")
   If Err <> 0 Then Set addinWorkbook = Nothing
   On Error GoTo 0
   If (addinWorkbook Is Nothing) Then rc = "": GoTo exitPoint

   'If @RISK 5.0.1 or higher is loaded, the version number is easy to get.  I
   'get it here using a late-bound method (using Application.Run) simply because
   'it is unlikely this code will have a reference to the @RISK 5.0 object
   'library if it needs to call this routine!  (In @RISK 5.0.0, itself, the call
   'RiskGetAutomationObject didn't exist, so I must look especially for @RISK
   '5.0.0 below.)

   On Error Resume Next
   rc = Application.Run("Risk.xla!RiskGetAutomationObject").ProductInformation.Version()
   On Error GoTo 0
   If rc <> "" Then GoTo exitPoint

   'Now we need to distinguish between @RISK 5.0.0 and @RISK 4.x.
   'In the former case the routine RiskGetInterfaceMode should exist.  In the
   'latter calling that routine will raise an error.

   On Error Resume Next
   dummyValue = Application.Run("Risk.xla!RiskGetInterfaceMode")
   If (Err <> 0) Then rc = "4.x" Else rc = "5.0.0"
   On Error GoTo 0

exitPoint:

   On Error GoTo 0
   GetAtRiskVersion = rc

End Function

Additional keywords: XDK

Last edited: 2015-08-31

This page was: Helpful | Not Helpful