← HomeSeries
Software Through the Ages
EPISODE 36 · 1983 → today

Office macros: from Lotus 1-2-3 to VBA, Apps Script and Tally TDL

The spreadsheet made calculation automatic; macros made the user's own keystrokes automatic. From Lotus 1-2-3's keystroke macros to Visual Basic for Applications, office macros let accountants, engineers and clerks build their own tools without being programmers. They also opened the door to a generation of macro viruses, which is why today's Office blocks downloaded macros by default. Indian business software has its own example: Tally's definition language, TDL.

1983
Lotus 1-2-3 keystroke macros
1992
Excel 4.0 macro sheets (XLM)
1993
VBA arrives in Excel 5.0
1995
Concept: the first widespread Word macro virus
2009
Google Apps Script
2022
Office blocks macros in files from the internet by default

01The requirement: let users automate their own documents

RequirementWhyWhat macros offered
Repeat keystroke sequencesMonthly reports needed the same 50 commands every timeRecorded keystroke macros
Custom functions and formsEach office has its own calculations and data entryUser-defined functions, dialog boxes and buttons
Link applicationsData moves from Excel to Word letters and Outlook e-mailsOne macro language across the Office suite (VBA)
No separate programming toolsUsers had Office, not compilersAn editor built into the application
Share the automationThe tool should travel with the documentMacros stored inside the file — which also let viruses travel

02From keystrokes to VBA

1983 — Lotus 1-2-3 macros. A macro was simply text typed into cells — the keystrokes of the slash-menu commands — named with a backslash and a letter. Pressing Alt+A ran \A. Later versions added {IF}, {BRANCH} and {GETNUMBER}, making it a small programming language. Whole accounting systems were built this way.
\A   {GOTO}A1~/WCS12~{DOWN}/RFC2~D2..D20~
Go to A1, set column width 12, move down, format D2:D20 as fixed with 2 decimals.
1980s — WordPerfect and WordStar macros. Word processors recorded keystrokes too; WordPerfect 5 (1988) had a full macro language used for legal and office templates.
1989 — WordBasic. Word for Windows 1.0 included a BASIC dialect that controlled every Word command.
1992 — Excel 4.0 macro sheets (XLM). Macros written as formulas on special sheets: =SELECT("R1C1"), =FORMAT.FONT(,,TRUE). Excel still recognises them; attackers revived them around 2020, and Microsoft restricted them by default in January 2022.
1993 — Visual Basic for Applications. VBA, derived from Visual Basic (Episode 10), arrived in Excel 5.0. Office 97 put VBA and its editor (Alt+F11) into Word, Excel, PowerPoint and Access, and companies licensed VBA for AutoCAD, SolidWorks, CorelDRAW and others (Episode 38).
2008–2011 — VBA on the Mac. Office 2008 for Mac dropped VBA; it returned in Office 2011 after strong complaints from users.
2009 → — Cloud scripting. Google Apps Script (JavaScript) automates Sheets, Docs and Gmail. Microsoft's Office Scripts (TypeScript, 2020) automate Excel on the web, and Python in Excel (2023–24) runs Python in cells on Microsoft's cloud.

03Try it: record a macro

Excel's macro recorder (View → Macros → Record) writes code for whatever you do. Click the actions below on the test log; the "recorder" writes the equivalent VBA, Google Apps Script or Excel Office Script.

The real recorder writes clumsier code (lots of Select and Selection); good macros, like these, act on ranges directly.

04Macro viruses and how Office fought back

Because macros live inside documents and can run automatically when a file opens (AutoOpen, Workbook_Open), they became an ideal virus carrier.

YearEvent
1995Concept, the first widespread Word macro virus, spread through shared documents worldwide within months.
1999Melissa used Word VBA to mail itself to the first 50 Outlook contacts (Episode 32).
1997–2007Macro security levels, digital signatures and, with Office 2007, separate .docm/.xlsm formats for files with macros; plain .docx/.xlsx cannot contain them.
2010Protected View opens downloaded files read-only; the yellow "Enable Content" bar appears.
2014–2021Banking trojans such as Emotet persuaded users to click "Enable Content" in fake invoices.
2022Microsoft restricted Excel 4.0 macros in January, then made Office block VBA macros in files carrying the "Mark of the Web" (downloaded or e-mailed) — with no enable button — for Word, Excel, PowerPoint, Access and Visio, from version 2203.
Safe practice: keep your own macros in trusted locations or sign them; never enable macros in a file that arrived by e-mail unless you know exactly what it does; prefer .xlsx for files you send to others.

05An Indian macro language: Tally's TDL

Tally (Episode 31) took a different route. The product itself is described in Tally Definition Language (TDL), a non-procedural language of definitions — menus, reports, forms, parts, lines and fields — plus actions and functions. Tally partners write TDL files to add fields, reports, invoice formats, workflows and integrations; TallyPrime loads them at start-up without changing the core program. TallyPrime Developer is the official editor and compiler, and Tally lists hundreds of ready-made extensions.

The traditional first TDL program adds a menu item that opens a report showing one line of text. It shows the structure every TDL report follows: Report → Form → Part → Line → Field.

;; Hello.tdl — adds "Hello Report" to the Gateway of Tally menu
[#Menu: Gateway of Tally]
    Add  : Item : Hello Report : Display : Hello Report

[Report: Hello Report]
    Form   : Hello Form

[Form: Hello Form]
    Parts  : Hello Part

[Part: Hello Part]
    Lines  : Hello Line

[Line: Hello Line]
    Fields : Hello Field

[Field: Hello Field]
    Set As : "Hello from TDL - Test Lab accounts"
    Width  : 60

Load it from F1: Help → TDL & Add-On → Manage Local TDLs in TallyPrime (menu names vary by release). Learn TDL on a test company, not your live books; Tally offers a free "TDL Essential" course.

06Ready-to-use macros

Paste VBA into the Excel editor (Alt+F11 → Insert → Module), save as .xlsm, and run with Alt+F8. Try them on copies of your files.

A. Merge every CSV in a folder into one sheet (Excel VBA)

Sub MergeCsvFiles()
    ' Import every CSV in a folder into a new sheet; column A records the file name.
    Dim folder As String, f As String
    Dim ws As Worksheet, src As Range, nextRow As Long, n As Long
    folder = "D:\Archive\Data\"                 ' must end with a backslash
    Set ws = ThisWorkbook.Worksheets.Add
    nextRow = 1
    Application.ScreenUpdating = False
    f = Dir(folder & "*.csv")
    Do While f <> ""
        Workbooks.Open folder & f
        Set src = ActiveWorkbook.Worksheets(1).UsedRange
        If nextRow > 1 Then                     ' keep the header only once
            If src.Rows.Count < 2 Then GoTo NextFile
            Set src = src.Offset(1).Resize(src.Rows.Count - 1)
        End If
        n = src.Rows.Count
        src.Copy ws.Cells(nextRow, 2)
        ws.Cells(nextRow, 1).Resize(n).Value = f
        nextRow = nextRow + n
NextFile:
        ActiveWorkbook.Close SaveChanges:=False
        f = Dir()
    Loop
    Application.ScreenUpdating = True
    MsgBox (nextRow - 1) & " rows merged into sheet " & ws.Name
End Sub

B. Save every sheet as its own PDF (Excel VBA)

Sub ExportSheetsToPdf()
    ' Writes one PDF per worksheet next to the workbook (save the workbook first).
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=ThisWorkbook.Path & "\" & ws.Name & ".pdf", _
            Quality:=xlQualityStandard, OpenAfterPublish:=False
    Next ws
    MsgBox "PDFs saved in " & ThisWorkbook.Path
End Sub

C. E-mail a daily summary from a Google Sheet (Apps Script)

// Extensions → Apps Script; then add a daily time-driven trigger.
function emailDailySummary() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Log');
  const rows = sheet.getDataRange().getValues().slice(1);          // skip header
  const temps = rows.map(r => Number(r[3])).filter(v => !isNaN(v));  // column D
  const body = 'Runs logged: ' + rows.length +
               '\nMaximum oil temperature: ' + Math.max(...temps) + ' °C';
  MailApp.sendEmail(Session.getActiveUser().getEmail(), 'Daily test summary', body);
}

D. Bold the header row (LibreOffice Basic)

Sub BoldHeader
    ' Tools → Macros → Edit Macros; works in LibreOffice Calc.
    Dim sheet As Object
    sheet = ThisComponent.Sheets.getByIndex(0)
    sheet.getCellRangeByName("A1:D1").CharWeight = com.sun.star.awt.FontWeight.BOLD
End Sub

07Today's choices

ToolLanguageRuns whereBest for
VBAVisual BasicDesktop Office (Windows, Mac)Existing workbooks, Office-to-Office automation; no longer developed but fully supported
Office ScriptsTypeScriptExcel on the web and desktop (Microsoft 365)Cloud workbooks; can be run by Power Automate (Episode 39)
Apps ScriptJavaScriptGoogle's cloudSheets, Forms, Gmail and Drive automation
LibreOffice Basic / PythonStarBasic, PythonLibreOffice desktopOpen-source office automation (Episode 18)
Python (openpyxl, pandas)PythonAnywhere, outside ExcelGenerating and analysing many workbooks without opening Excel
Tally TDLTDLTallyPrimeAccounting customisation and integration in Indian businesses

08Version explorer

Blue chips: desktop macro languages. Amber chips: cloud and business scripting.

09Lessons for engineers

  1. Record, then rewrite. The recorder shows the object names; clean code acts on ranges without selecting them.
  2. Keep macros out of shared files. Put tools in a personal macro workbook or an add-in; send colleagues plain .xlsx.
  3. Document the macro in the workbook. A sheet named "README" with purpose, author and version saves the next user.
  4. Know when to leave Excel. When a macro grows past a few hundred lines or handles millions of rows, move to Python or a database (Episode 05).

Sources & further reading

  1. Microsoft 365 Blog — Blocking internet macros by default in Office (Feb 2022)
  2. Netskope — VBA blocked by default in files from the internet
  3. Tally Solutions — What is TDL? · TallyPrime Developer
  4. Wikipedia — Visual Basic for Applications · Macro virus · Lotus 1-2-3
  5. Google Apps Script · Office Scripts