To use XMinifier and XCombiner, use the text boxes and buttons below. The gray box contains the combined and minified code, while the white boxes are where you can input VBA code.
XMinfier is a tool used to minify VBA code by removing excess syntax features (such as excess whitespace and comments) in order to reduce the size of the code. This can be useful when including VBA code into Excel, Word, and PowerPoint files, as it can reduce the total file size by reducing the amount of space that the VBA code occupies. In some cases the reduction in VBA code size can be substantial. In one case I was able to reduce the size of my VBA code from ~150KB down to ~50KB, saving a significant amount of space in the total file.
In addition to XMinifier, XCombiner can be used to combine all your VBA code modules into a single file, removing excess Attribute names, and combining Option settings found in mutliple modules. This can be useful when sending distributing your source code, as the entire source code can be imported in a single file instead of multiple files. However, there are limitations to combining VBA source code files:
Option Statements (such as Option Explicit) are used on a module by module basis, and when combining two VBA modules that have different Option Statements, it is likely that the combined code will not function properly. You should only use XCombiner on modules with the same Option Statements or with no Option Statements.
References to Module Names
In some cases, VBA source code can be built to include the name of the module that contains a function you are calling. For example, if in ModuleA you have a function called AddTwo and you call it in ModuleB via the call ModuleA.AddTwo, then once combined and error will be thrown when running the code since ModuleA will no longer exist. As a result, only modules that don't have references to other modules should be combined, or after combining modules, the references to the other modules should be removed (in the above example by running a Find/Replace in the combined module to find "ModuleA." and replace with "").
XCombiner and XMinifier are open source software, and the source code for each program can at the official github pages:
Where does my code go?
The MIT License (MIT)
Copyright © 2020 Anthony Mancini
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.