I've released a personal-finance workbook for Microsoft 365 on Windows, into the public domain (CC0 1.0). It has about 63K lines of VBA (around 45K of them code, the rest comments and blank lines) in 26 standard modules, 44 sheet and ThisWorkbook modules, and one UserForm. I'd really welcome a look from VBA enthusiasts on here.
I'd been using an Excel workbook for the past 25 years or so for my personal finances and finally decided around a year ago to step up my game and see what could be improved in the automation dept. I started creating macros back in the 90s and totally nerded out back then on Excel. For the last 10 years or so, I decided to study VBA more seriously, reading instruction pubs with my morning coffee and tinkering when I could. Since I'd used MS Money and Quicken back in the day, but was frustrated with both for certain scenarios, I gave up and relied on what I could do in Excel instead. I designed and tested it for almost a year (others are stronger with skinning the UI; I concentrated on the functional aspects) and got some AI time in last month for resolving a few things I needed help with.
Some of the design choices:
- Excel Tables with calculated columns do most of the math. VBA builds the loan amortization schedules and the debt-payoff projections, runs the on-sheet input "forms", and does all the add, edit and delete work on those tables.
- No cell addresses in the code: it finds worksheet locations by named range, or by table and column names (there are a few cell A1 references, selecting the top-left cell for scroll returns).
- Status messages are written as a value plus a severity code, and conditional formatting does all the coloring. The code never sets a color directly.
- A ton of BeginBatch/EndBatch pairs manage calculation, events, screen updating and Esc-key presses. Only the outermost pair switches them.
- "Import from Previous Version" copies the old workbook to the temp folder and opens that copy read-only with 'AutomationSecurity' set to force-disable, so the old file is never touched and its macros can't run.
- A build routine scrubs personal data, writes shipped defaults, and checks the result (personal settings blank, grids empty, help text complete, no external links) before saving the release copy.
Here's a BeginBatch/EndBatch pair sample:
Public Sub BeginBatch(Optional ByVal notFromMacroList As Boolean = False)
' The optional argument is never used: a routine that takes one is not
' offered in Alt+F8's list of macros, and this one is never run by hand
' (it would leave calculation on hold and the sheets' events off).
' The outermost batch also turns off interruption by Esc and
' Ctrl+Break, so an action is never stopped partway through its
' writes. Excel turns interruption back on by itself as soon as no
' macro is running; EndBatch leaves it alone, because an action's
' work often goes on after its batch closes.
If mBatchDepth = 0 Then
Application.EnableCancelKey = xlDisabled
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
End If
mBatchDepth = mBatchDepth + 1
End Sub
Public Sub EndBatch(Optional CalcNow As Boolean = True)
' The outermost EndBatch turns events and calculation back on and
' shows the screen unless a navigation button is holding it until
' the sheet it is showing has refreshed (ShowSheet).
If mBatchDepth > 0 Then mBatchDepth = mBatchDepth - 1
If mBatchDepth = 0 Then
Application.EnableEvents = True
If CalcNow Then Application.Calculation = xlCalculationAutomatic
If Not mNavHold Then Application.ScreenUpdating = True
End If
End Sub
Where I'd most value another set of eyes:
- Performance. Some routines still loop over ListRows cell by cell instead of reading 'DataBodyRange' into an array once.
- The OFX/QFX/CSV parsers, especially with non-U.S. number and date formats.
- Error handling. There are over 400 'On Error Resume Next' lines, which is more than I'd like. I'd welcome opinions on which ones should become real error handling.
On safety, since it's a macro file:
- There are no 'Declare' statements, no 'Shell' calls, and no web requests.
- 'Kill' deletes only two things: old backups beyond the number the user wants to keep, and the importer's own temporary copy.
- 'CreateObject' makes only 'Scripting.Dictionary' and 'ADODB.Stream'. The stream writes the CSV export as UTF-8, and decodes an imported OFX/QFX file whose header names a character set other than UTF-8 (in memory; it doesn't write anything).
- It reads six Windows environment variables, all standard folder locations: 'LOCALAPPDATA' (the fallback backup folder); 'OneDrive', 'OneDriveConsumer' and 'OneDriveCommercial' (to find the local folder of a workbook kept in OneDrive); and 'TEMP', or 'TMP' if 'TEMP' is blank (the importer's temporary copy). My release-build routine also falls back to 'TEMP' for its report.
- A plain-text listing of every module is in the download and on the release page, so you can read it all without opening Excel.
Most of the testing so far is mine, with help from several co-workers and friends, so testers are welcome too. I'm happy using it for my own stuff. The zip download includes a sample-data copy to try things on, and I have an Issues page set up (https://github.com/rsullivan-summetry/Summetry/issues).
Project page: https://github.com/rsullivan-summetry/Summetry