Skip to content

Software License Dongle for VBA, Excel and Access

Serious Excel and Access solutions get sold, copied and passed around, and VBA offers essentially no protection of its own — project passwords are a formality. A dongle changes the economics.

64-bit Office

Import the supplied .bas module, which declares the API with PtrSafe, and deploy the 64-bit library.

Dim h As Long
Dim license() As Byte

If KeyNubDeviceCount() = 0 Then
    MsgBox "Please plug in your KeyNub license dongle."
    Exit Sub
End If

h = KeyNubOpen()                     ' first dongle found
Debug.Print "Serial: " & KeyNubVerifyGenuine(h)

KeyNubSessionOpen h
license = KeyNubRecordRead(h, "license")
KeyNubSessionClose h

KeyNubClose h                        ' always: the library holds 32 handlesCode language: VB.NET (vbnet)

32-bit Office: use COM instead

This is the one thing worth reading carefully. The core library uses the cdecl calling convention; VBA’s Declare emits stdcall. In a 64-bit process there is only one calling convention, so the difference does not exist and the Declare module is correct. In a 32-bit process neither side cleans up the arguments and the stack pointer drifts with every call.

This is a property of the calling convention, not something a careful Declare can work around: VBA has no equivalent of the CDecl keyword on Windows. So on 32-bit Office, use the COM interface instead — it is the same object VB6 uses, it works from VBA unchanged, and the calling convention stops being your problem. On 64-bit Office the Declare module is correct and is what we recommend.

Set dongle = CreateObject("KeyNub.Dongle")Code language: VB.NET (vbnet)

Gate on data, not a message box

A MsgBox and an Exit Sub are trivially deleted — anyone who can open the VBA editor can remove them. Encrypt the rate tables, pricing constants, formulas or thresholds the workbook actually needs, and decrypt them through the dongle at run time. Then a copied workbook opens perfectly and computes nothing.

Code

Runnable sample: vba/verify_and_read.bas. Binding source: bindings/vba. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.

All supported languages · All industries · Buy a KeyNub · Ask us something