'================================================================= ' PUBLIC MACROS – called from the Dashboard buttons '================================================================= Public Sub ShowInvoiceForm() frmInvoice.Show vbModal End Sub
'================================================================= ' UI UNLOCK – enables the buttons on the Dashboard sheet '================================================================= Private Sub UnlockUI() Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("Dashboard") Dim btnNew As Shape, btnSearch As Shape On Error Resume Next Set btnNew = ws.Shapes("btnNew") Set btnSearch = ws.Shapes("btnSearch") On Error GoTo 0 If Not btnNew Is Nothing Then btnNew.OnAction = "ShowInvoiceForm" If Not btnSearch Is Nothing Then btnSearch.OnAction = "ShowSearchForm" 'Optionally hide the activation prompt button (if you placed one) Dim btnActivate As Shape Set btnActivate = Nothing On Error Resume Next Set btnActivate = ws.Shapes("btnActivate") On Error GoTo 0 If Not btnActivate Is Nothing Then btnActivate.Visible = msoFalse End Sub
'================================================================= ' GLOBAL SETTINGS – adjust as needed '================================================================= Private Const KEY_LENGTH As Long = 16 ' length of a plain key (characters) Private Const KEY_HASH_ALGO As String = "SHA256" ' only SHA256 is used internally invoice manager for excel activation key
| Control | Name | Type / Caption | Size / Position (suggested) | |---------|---------------|----------------|-----------------------------| | Label | lblDate | Caption: “Date” | top = 10, left = 10 | | TextBox | txtDate | – | top = 10, left = 80, Width = 120 | | Label | lblNo | “Invoice #” | top = 40, left = 10 | | TextBox | txtNo | – | top = 40, left = 80 | | Label | lblCust | “Customer” | top = 70, left = 10 | | TextBox | txtCust | – | top = 70, left = 80, Width = 200 | | Label | lblItems | “Items (one per line)” | top = 100, left = 10 | | TextBox | txtItems | MultiLine = True, Height = 80 | top = 100, left = 80 | | Label | lblAmt | “Amount” | top = 190, left = 10 | | TextBox | txtAmt | – | top = 190, left = 80 | | Label | lblTax | “Tax %” | top = 220, left = 10 | | TextBox | txtTax | – | top = 220, left = 80 | | Label | lblTotal | “Total” (calculated) | top = 250, left = 10 | | TextBox | txtTotal | Locked = True | top = 250, left = 80 | | CommandButton | btnSave | Caption: “Save” | top = 290, left = 80 | | CommandButton | btnCancel | Caption: “Cancel” | top = 290, left = 180 | Option Explicit
'================================================================= ' SHA‑256 → Base64 helper (uses MSXML for crypto) '================================================================= Private Function ComputeSHA256Base64(ByVal s As String) As String Dim xml As Object Set xml = CreateObject("MSXML2.DOMDocument.6.0") Dim hashObj As Object Set hashObj = CreateObject("System.Security.Cryptography.SHA256Managed") Dim bytes() As Byte bytes = StrConv(s, vbFromUnicode) ' UTF‑8 bytes Dim hashBytes() As Byte hashBytes = hashObj.ComputeHash_2((bytes)) 'Convert to Base64 Dim base64 As Object Set base64 = CreateObject("Microsoft.XMLDOM").createElement("b") base64.DataType = "bin.base64" base64.nodeTypedValue = hashBytes ComputeSHA256Base64 = base64.Text End Function 1️⃣ What the solution does | Feature |
'================================================================= ' ENTRY POINT – runs automatically when workbook opens '================================================================= Private Sub Workbook_Open() Call InitWorkbook Call PromptForActivation End Sub
You can drop the code into a new workbook, customize the worksheet layout to suit your business, and then distribute the file together with a list of valid keys (or a single key you generate for each customer). This implementation is not meant to be a high‑security DRM system – VBA can be read and altered by a determined user. It is, however, more than enough for basic “you‑must‑enter‑a‑key before you can use the tool” scenarios typical for internal tools, small‑business add‑ins, or prototype deployments. 1️⃣ What the solution does | Feature | Description | |--------|-------------| | Invoice entry form | A user‑form ( frmInvoice ) lets you capture the main invoice fields (Date, Number, Customer, Items, Amount, Tax, Total). | | Invoice list | All entered invoices are stored in a hidden worksheet called Invoices . | | Search / edit | A second form ( frmSearch ) lets you locate an invoice by number and optionally edit it. | | Activation‑key check | When the workbook opens, a modal dialog asks for a key. The key is validated against a simple algorithm (hash‑based) and, if valid, the rest of the UI becomes usable. Invalid or missing keys keep the workbook locked. | | Key management | All valid keys are stored (obfuscated) in the hidden sheet KeyStore – you can add/remove keys without touching the code. | | Lock‑down | The VBA project itself is password‑protected (you set it yourself) and the key‑check disables the ribbon items that launch the forms until a valid key is entered. | 2️⃣ Workbook layout (what you need to create) | Sheet name | Visibility | Purpose | |------------|------------|---------| | Invoices | Very hidden (via VBA) | Stores each invoice as one row. Columns: A:Date , B:Number , C:Customer , D:Items , E:Amount , F:Tax , G:Total . | | KeyStore | Very hidden | Column A holds the obfuscated (base‑64‑encoded) list of valid keys. | | Dashboard | Visible (optional) | A simple front‑page where you can place two buttons: “New Invoice” and “Search Invoice” . The buttons are wired to the macros ShowInvoiceForm and ShowSearchForm . | Tip: If you prefer a clean workbook, you can delete any extra sheets. The code only references the three above. 3️⃣ VBA code – copy‑paste it into a standard module (e.g., modInvoiceMgr ) Option Explicit | | Activation‑key check | When the workbook
'================================================================= ' INITIALISATION (hide sheets, create tables if missing) '================================================================= Public Sub InitWorkbook() Dim wsInv As Worksheet, wsKey As Worksheet '--- Invoices sheet ------------------------------------------------ On Error Resume Next Set wsInv = ThisWorkbook.Worksheets("Invoices") On Error GoTo 0 If wsInv Is Nothing Then Set wsInv = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) wsInv.Name = "Invoices" wsInv.Range("A1:G1").Value = Array("Date", "InvoiceNo", "Customer", "Items", "Amount", "Tax", "Total") wsInv.Visible = xlSheetVeryHidden End If '--- KeyStore sheet ------------------------------------------------ On Error Resume Next Set wsKey = ThisWorkbook.Worksheets("KeyStore") On Error GoTo 0 If wsKey Is Nothing Then Set wsKey = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) wsKey.Name = "KeyStore" wsKey.Visible = xlSheetVeryHidden End If End Sub