Main Page

'''This Wiki is a repository for VBA Code THAT works. Please do not under any circumstances post code that you have not tested and proved, otherwise your edits will be rolled backed and you will be banned.''' This wiki is to help people solve problems with code NOT frustrate them with crapware. Please document your code samples and explain how it works with remarks. = VBA =

Event-Handlers

 * DataTypeErrorTrap - Prevent non-numeric data from being entered in cell A1
 * Tock / StopClock - Start and stop cell A1 updated with time every second

Formulas

 * DaysHoursMinutes - Show total time as days, hours, and minutes
 * Spherical - Convert star data from the Cartesian to the spherical coordinate system

Functions

 * DaysInMonth - Calendar function not built into Excel
 * Gather - Combine elements of a range into one cell with custom delimiter
 * GetText - Strips numeric characters out of a cell
 * TopAvg - Compute average of highest n items in a range

Methods

 * Compare - Highlight data in set A that does not match set B
 * Convert2data - Convert a range of formulas to its present data
 * FindDupes - Highlight duplicate data
 * GrayEveryThirdRow - Apply gray background on every third row
 * IsFormula - Mark formula cells on a sheet

Procedures

 * BoldPos - Make only positive values in a selection bold
 * FillBlanks - Fill a column containing blanks with valid data
 * FillRnd - Fill 10 x 20 area with random numbers
 * MakeCheckerboard
 * Recenter - Put origin at next star on list and recalculate position data
 * Excel2Word - Copy data from Excel to a Word Document

Procedures

 * MakeConcordance - Build a list of every word used in Word document

Documentation

 * '''MS Access Object Model
 * VBA Glossary
 * VBA conceptual topics
 * VBA Language Reference

NT4 for Workstations

 * Excel97 - VBA 5.0

XP

 * Excel2003 - VBA 6.4

Wiki

 * MediaWiki Markup Language
 * Code Markup
 * Navigation Template
 * Barry (Talk)
 * Joel (Talk)

About !
Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven programming language Visual Basic 6, which was discontinued in 2008, and its associated integrated development environment (IDE). Although Visual Basic is no longer supported or updated by Microsoft, the VBA programming language was upgraded in 2010 with the introduction of Visual Basic for Applications 7 in Microsoft Office applications.

Visual Basic for Applications enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). It supersedes and expands on the abilities of earlier application-specific macro programming languages such as Word's WordBASIC. It can be used to control many aspects of the host application, including manipulating user interface features, such as menus and toolbars, and working with custom user forms or dialog boxes.

As its name suggests, VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library. However, VBA code normally can only run within a host application, rather than as a standalone program. VBA can, however, control one application from another using OLE Automation. For example, VBA can automatically create a Microsoft Word report from Microsoft Excel data that Excel collects automatically from polled sensors. VBA can use, but not create, ActiveX/COM DLLs, and later versions add support for class modules.

VBA is built into most Microsoft Office applications, including Office for Mac OS X (except version 2008), and other Microsoft applications, including Microsoft MapPoint and Microsoft Visio. VBA is also implemented, at least partially, in applications published by companies other than Microsoft, including ArcGIS, AutoCAD, CorelDraw, LibreOffice, Reflection, SolidWorks, and WordPerfect.

The Object Model Idea
Developers organize programming objects in a hierarchy, and that hierarchy is called the object model of the application.

The definition of an object is called a class, so you might see these two terms used interchangeably. Technically, a class is the description or template that is used to create, or instantiate, an object.

Once an object exists, you can manipulate it by setting its properties and calling its methods. If you think of the object as a noun, the properties are the adjectives that describe the noun and the methods are the verbs that animate the noun. Changing a property changes some quality of appearance or behavior of the object. Calling one of the object methods causes the object to perform some action.

Applications
Microsoft allows the user to create, edit, debug and compile code for the following Applications.

Version history

 * VBA was first launched with MS Excel 5.0 in 1993. It became an instant success among developers to create corporate solutions using Excel. Inclusion of VBA with Microsoft Project, Access and Word replacing AccessBASIC and WordBASIC respectively made it more popular.
 * VBA 4.0 is the next famous release with a totally upgraded version compared to previous one. Released in 1996, it is written in C++ and became an object oriented language.
 * VBA 5.0 was launched in 1997 along with all of MS Office 97 products. The only exceptions for this was Outlook 97 which used VBScript to automate ● things.
 * The Year 1999 saw the launch of VBA 6.0, notably with support for COM add-ins in Office 2000. VBA 6.2 was released alongside Office 2000 SR-1.
 * VBA 6.3 was released after Office XP, VBA 6.4 followed Office 2003 and VBA 6.5 was released with Office 2007.
 * Office 2010 includes VBA 7.0. There are no new features in VBA 7 for developers compared to VBA 6.5 except for 64-bit support. However, after VBA 6.5/Office 2007, Microsoft stopped licensing VBA for other applications.
 * Office 2013 and Office 2016 include VBA 7.1.