This is a collection of VBA utilities that I wrote in the last 20 years. I did this because I really love simplicity and elegance and far too many code examples on the internet have neither of these.
So, I hope you will find these utilities useful. Use them as you wish. Just include a copyright notice that references me. Enjoy.
The utilities are categorized in the following way:
A class to read an access lock file in order to find out which computer is holding a lock on the access database. This can either be the database that this class is part of or another database file. It supports mdb and accdb files.
Wrapper around ADO fields for easier property access.
Wrapper around ADO tables for easier property access.
Easily set and get DAO properties.
Make a copy of a database and keep a specified number of copied files.
Manage compression of an Access database.
Get and change the path to a linked table.
Show and clear an Access status line. The status line is automatically cleared when the class is destroyed.
A universal hashing class. It calculates SHA-1 and SHA-2 hashes (with 256, 384 and 512 bits length) and also HMAC values with these hashes. It uses the Windows CNG (Crypto Next Generation) API, so all calculations are done by Windows.
Calculates PBKDF2 hashes from passwords. The algorithm "Password based key derivation function No. 2" is defined in RFC 2898. It can be used with several hash algorithms. This implementation provides MD4, MD5, SHA-1, SHA-2-256, SHA-2-384 and SHA-2-512 (SHA-2). Recommended is the method Pbkdf2WithSHA256
. The iteration count should be chosen so that calculating a PBKDF2 hash takes 0.5 to 0.8 seconds. The salt should be unique for every user and should have a length of at least 8 bytes.
Secure CNG random number generator which is a wrapper around the Windows CNG (Crypto Next Generation) RNG API and uses the BCryptGenRandom function.
When calling Windows API functions one gets a return code. In order to find out what it means and present that return code as a text to the user this class translates the return code to a string. It just asks Windows what the meaning of the return code ist. BTW, it also has a method to handle message templates with positional parameter substitution.
This class handles custom properties for an Excel workbook.
This class handles custom properties for an Excel worksheet.
Get information about a drive, i.e. what type it is and whether it is a network drive.
Managing file compression is horribly complicated under Windows as this is not an attribute but something that is achieved by issuing I/O control command. This class puts a simple wrapper around the complexity of handling compressed files. One can create a compressed file and read, set and clear the compression state of a file.
Helper class to generate a unique random file name.
A simple record class used in the FTPClient.
A simple FTP client for VBA programs. It has the following public methods.
- Connect
- Disconnect
- GetFile
- PutFile
- CreateDirectory
- RemoveDirectory
- DeleteFile
- GetCurrentDirectory
- SetCurrentDirectory
- DirFiles
A little helper class to calculate interpolations between different navigational bearings.
Helper class to calculate distances and bearings on a sphere when the positions (latitude, longitude) are known.
Adds missing trigonometric functions to VBA:
- ArcCos
- ArcSin
- ArcTan2
- RadiantToDegree
- DegreeToRadiant
Pure VB implementation of a Base64 converter. Converts byte arrays to and from Base64 representation.
Implementation of a Base64 converter as a wrapper around crypt32.dll API calls. Converts byte arrays to and from Base64 representation.
Converts byte arrays to and from hexadecimal string representation.
Converts integer to and from roman number representations.
Class to set the currently running processes priority class to give it a higher or lower scheduling priority.
Get Windows special folder names.
Get some system informations.
An implementation of the insertion sort algorithm.
Implementation of the insertion sort algorithm where not the data array is sorted but an index into the data array. This is especially useful when moving data is an expensive operation like e.g. for strings.
A pure quicksort implementation.
Pure quicksort implementation where not the data array is sorted but an index into the data array. This is especially useful when moving data is an expensive operation like e.g. for strings.
An optimized quicksort implementation. Here quicksort is combined with insertion sort to make the implementation faster.
Optimized quicksort implementation where not the data array is sorted but an index into the data array. This is especially useful when moving data is an expensive operation like e.g. for strings.
An implementation of a stack. Used by the quicksort type sorter classes.
An implementation of one of the most important classes that is missing in VBA: A string builder. It allows method chaining like in e.g. sb.SetTo("Content").Append(aVar).Append(anotherVar)
.
Converts VBA strings from and to UTF-8 encoding. Note that the UTF-8 values are byte arrays, not strings. Storing UTF-8 encodings in VBA strings is seriously wrong.
Converts VBA timestamps from and to Unix timestamps or local time from and to UTC time.
A high precision stopwatch that uses the Windows Performance Counter which has a resolution better than 0.000001 seconds (1µs).
Suspend program execution for a specified amount of time or for a random amount of time while keeping the application responsive.