Migration guide: Velixo Classic VBA interop macros to Velixo NX
Overview
Using the latest version of Velixo Tools, you can automate Velixo NX operations using VBA, just like Velixo Classic. We expect this to be a significant enabler for existing partners, service providers, or VBA power users planning a migration to Velixo NX from Velixo Classic.
Today, can keep your VBA scripts operational while taking advantage of Velixo NX’s exclusive functions and features.
Follow the steps below to enable automating Velixo NX via VBA. Ensure that you adapt your existing scripts according to the guide to ensure they continue to work as intended.
For the Velixo NX installation guide, refer to our dedicated page.
Install Velixo Tools (version 7.1.715 or newer)
Follow the Velixo Tools installation guide.
Add Velixo Tools as a reference in the VB Editor
To enable support for Velixo’s VBA commands in your workbook:
Open the workbook in Excel.
Open the Visual Basic Editor – Alt + F11.
Go to Tools → References…
On the list of available references, find Velixo_NX_Tools, check the box.
Make sure the box next to Velixo_Reports, if it exists, is unchecked.
Click OK.
Adapt references to use the Velixo_NX_Tools library
Since your Velixo Classic-compatible scripts created the VelixoObj
object using the Velixo_Reports
COM library, which you replaced with Velixo_NX_Tools
in the previous step, all type references and ProgID strings in your scripts need to match this change:
Change instances of class references from
Velixo_Reports.VBA
toVelixo_NX_Tools.VBA
Change referenced ProgID strings from
"Velixo.Reports.Vba"
to("Velixo.NX.Tools.Vba")
Example
Original script used with Velixo Classic:
Sub CopyWorkbookWithoutFormulas()
Dim velixoObj As Velixo_Reports.VBA
Set velixoObj = CreateObject("Velixo.Reports.Vba")
Application.DisplayAlerts = False
velixoObj.CopyWorkbookWithoutFormulas "C:\The\Desired\Path\FileName.xlsx"
Application.DisplayAlerts = True
MsgBox "Workbook copied without formulas"
End Sub
Equivalent script with references updated to leverage Velixo NX and Velixo Tools:
Sub CopyWorkbookWithoutFormulas()
Dim velixoObj As Velixo_NX_Tools.VBA
Set velixoObj = CreateObject("Velixo.NX.Tools.Vba")
Application.DisplayAlerts = False
velixoObj.CopyWorkbookWithoutFormulas "C:\The\Desired\Path\FileName.xlsx"
Application.DisplayAlerts = True
MsgBox "Workbook copied without formulas"
End Sub
Voilá! While the steps above should be enough to keep your existing VBA scripts operational, with an important exception of writeback, which requires completing the recommended follow-up steps below.
Even if you don’t automate writeback via VBA, we strongly recommend following the optional migration steps below to convert your code to asynchronous callbacks. In some cases, using Classic-compatible synchronous functions may result in Excel becoming unresponsive. This happens because Velixo Tools and Velixo NX share Excel’s user interface processing thread.
Recommended: adapt your scripts to use asynchronous callbacks
To prepare the VBA scripts you used for automating Velixo Classic, replace the following Velixo VBA commands with their asynchronous counterparts by adding the Async
suffix to the command names:
Synchronous command | Asynchronous counterpart |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The ActiveFunctionsCount
command does not interfere with Excel’s calculations and can be used safely despite being synchronous.
To keep the scripts' behavior unaltered after switching to asynchronous versions of commands, three more alterations are necessary to maintain the original execution order:
Extract VBA statements that succeeded your (formerly) synchronous command to a separate VB module (Insert → Module in VB Editor).
Add an
AddOperationCompleteCallback
call that references the new, asynchronous method before the command itself.Add a
RemoveOperationCompleteCallback
call to the newly-added VB module to prevent multiple subscription and execution of callbacks.
Example
Original, Velixo Classic-compatible VBA script leveraging the synchronous CopyWorkbookWIthoutFormulas
command:
Sub CopyWorkbookWithoutFormulas()
Dim velixoObj As Velixo_Reports.VBA
Set velixoObj = CreateObject("Velixo.Reports.Vba")
Application.DisplayAlerts = False
velixoObj.CopyWorkbookWithoutFormulas "C:\The\Desired\Path\FileName.xlsx"
Application.DisplayAlerts = True
MsgBox "Workbook copied without formulas"
End Sub
Adapted, Velixo NX-compatible VBA script leveraging the asynchronous CopyWorkbookWIthoutFormulasAsync
command, preceded by an AddOperationCompleteCallback
call referencing the command:
Public Sub CopyWorkbookWithoutFormulas()
Dim velixoObj As Velixo_NX_Tools.VBA
Set velixoObj = CreateObject("Velixo.NX.Tools.Vba")
Dim noArgs() As Variant
velixoObj.AddOperationCompleteCallback ActiveWorkbook, VbaCommandName_CopyWorkbookWithoutFormulas, "ShowStatusCopyWithoutFormulas", noArgs
Application.DisplayAlerts = False
velixoObj.CopyWorkbookWithoutFormulasAsync "C:\The\Desired\Path\FileName.xlsx"
Application.DisplayAlerts = True
End Sub
Note that in the example below, when adding a callback via AddOperationCompleteCallback
, the type of operation we’re “subscribing” to does not contain the Async
suffix. This is expected. For instance: VbaCommandName_WritebackCurrentWorksheet
And a VB module (Insert → Module in VB Editor) containing the callback along with unsubscription logic:
Sub ShowStatusCopyWithoutFormulas()
MsgBox "Workbook copied without formulas"
Dim velixoObj As Velixo_NX_Tools.VBA
Set velixoObj = CreateObject("Velixo.NX.Tools.Vba")
Dim noArgs() As Variant
velixoObj.RemoveOperationCompleteCallback ActiveWorkbook, VbaCommandName_CopyWorkbookWithoutFormulas, "ShowStatusCopyWithoutFormulas", noArgs
End Sub