The VBA Code Library is where you’ll find all my stand-alone VBA macros that don’t require a detailed tutorial on my VBA Tutorials Blog.
These macros range from the useful to the quirky, so go ahead and explore! Some may be Excel macros, some may be Word macros and some may be others or universal VBA macros. Each one will have a brief introduction, followed by a self-contained VBA code. I encourage you to adapt them to fit the needs of your particular application!
-
Faster Alternatives to VBA PageSetup
You can speed up the slow Worksheet.PageSetup object by disabling the Application.PrintCommunication property and exploring the Excel 4.0 PAGE.SETUP function.
-
A VBA UDF to Enhance Excel's CELL and INFO Functions
This custom VBA function improves upon Excel's built-in CELL and INFO functions by returning information not available in the CELL and INFO functions.
-
Display Screen Size and Other Metrics with VBA UDF
This VBA function will return the screen size and other display metrics for the screen containing Excel's ActiveWindow. It even supports multi-monitor configurations.
-
Play System Sounds and WAV Files With VBA PlaySound
The VBA Beep statement is limited for audible signaling, but Windows' PlaySound function can be used to play standard system sounds or any WAV file using VBA.
-
Check if folder exists, then create folder with VBA MkDir
This tutorial will show you how to check if a folder exists and create the folder with the VBA MkDir statement if it doesn't exist.
-
VBA - Remove Duplicates from Array
In this VBA tutorial, I show you two ways to remove duplicates from an array. The first method uses the scripting dictionary and the second uses collections.
-
Return Position of Element in VBA Array
Return the position of an element in an array with this function from the VBA code library. This UDF is a great tool to have when working with arrays.
-
VBA Column Number to Letter
Use this VBA function to convert a column number to a letter. This is useful if you need to build a range and you want to do so with the A1 notation.
-
Excel VBA Delete Blank Rows
Delete blank rows in Excel with this VBA macro. There are dozens of way to delete blank rows in Excel. The macro in this tutorial is a fast way to do it.
-
Find the Closest Number in a Range with this VBA UDF
Pass this VBA function a range of cells and a number that you want to find a number closest to and it will return the value in the range closest to your target.
-
VBA Dir Function to Check if File Exists
Use the VBA Dir function to check if a file exists. The VBA Dir function returns the name of a valid file, so you can use it to test whether a file exists.
-
Match Value in Range to Same Position in Another Range
Return the value in one range based on the relative position of a value in another range without the index, match or offset functions by using this Excel UDF.
-
Macro to Enable Trust Access to the VBA Project Object Model
You can programmatically enable trust access to the VBA project object model with this macro. Doing so allows you to add modules and write macros from a macro.
-
Use VBA to Mute, Unmute, Volume Up and Volume Down
Did you know you can use VBA to control your computers speakers? This tutorial shows you how to mute and unmute your volume and turn your volume up and down.
-
Convert Decimal Time to Hours Minutes Seconds with VBA
This VBA function converts decimal times in Excel to words. 10.5 becomes 10 Minutes 30 Seconds. It can convert base times given in hours, minutes or seconds.
-
Use VBA ShellExecute to Open URL in Default Browser
Use the VBA ShellExecute function to open a URL in the default browser. VBA ShellExecute is a better choice than opening each website in internet explorer.
-
VBA Beep Sound on Error
The VBA Beep function lets you play a system beep sound whenever you like. VBA Beep usually comes through your speakers so make sure your volume is up.
-
VBA Count Files in Folder
Use this VBA macro to count the files in a folder. This macro can return the number of total files in a folder or the number of files of a certain type.
-
VBA Loop Through Files in Folder
Loop through files in a folder with this VBA macro. Use it anytime you need to check each file in a folder or when you want to list the files in a folder.
-
Check if Value is in Array using VBA
Check if a value is in an array with this VBA function. Use it to look for a string in a string array, an integer in an integer array, and more.
-
VBA to Maximize Window in Left Monitor
Move your window to the left screen and maximize it with VBA. Placing your window in a consistent position is a must before using mouse control macros.
-
Open Folder using VBA and Show if Already Open
This macro opens a folder using VBA or shows the open window if the folder is already opened. Pass the macro a string with the folder you want to open.
Code More, Distract Less: Support Our Ad-Free Site
You might have noticed we removed ads from our site - we hope this enhances your learning experience. To help sustain this, please take a look at our Ultimate VBA Training Bundle. Each purchase directly supports this site, ensuring we can continue to offer you quality, distraction-free tutorials.