Wednesday, January 22, 2014

Introduction to Visual Basic for Applications

Alright guys!! I guess the time has come to go beyond the regular posts on Excel front end, into developer front. Before diving deep into developer stuff, I thought it's appropriate to look a little bit about Excel programming history first.

Some Technical Info

Excel programming language is called Visual Basic for Applications (VBA) which is a dialect of Visual Basic (VB). VB was released by Microsoft and quickly became famous for its ease of use to create application components.

Before VB, various macro languages were previously supplied with Office applications to automate tasks. It was Microsoft's idea to cut all those different macro languages and make one universal language to embed in applications. But VB is a separate programming language altogether and it needs to be purchased and installed separately to work with. Hence a cut down version of VB is made and named as VBA. That's how VBA was born and evolved.

VBA is distributed using host applications like MS Office products such as Excel, Word etc. So, writing code, saving and executing can only be done within a host application rather than as a standalone program. But you can use VBA to control and work with other VBA hosted applications. For example, if you are using VBA in Excel, you can open and read the contents of MS Word file. VBA is proprietary to Microsoft hence you cannot use VBA written program in any third party application.

VBA code is written in Visual Basic Editor (VBE). Code is then compiled by host application into an intermediate language called 'p-code' which then be executed by a virtual machine which is also hosted by host application. Code you write in VBA would almost look like common spoken English. We will see different terms used and appearance of VBA in forthcoming posts. 

Quick History
  • VBA was first launched with MS Excel in 1993. It became an instant success among developers to create corporate solutions using Excel.
  • 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++ language and became object oriented language.
  • VBA 5.0 was launched in 1997 along with all of MS Office 97 products. Only exceptions for this is Outlook which was using VBScript to automate things.
  • Year 1998 saw the launch of VBA 6.0 and continued to be supplied with MS Office suite.
  • Office 2010 is included with VBA 7.0. There is nothing much offered to developers from VBA 6.0 except for 64-bit support.
Once entered in the world of VBA, we will learn how to automate simple tasks, write bits of complex codes and custom made functions etc. We will dismantle the code to analyse what it means and how to develop Excel applications using VBA. We will also see a series of practical situations and write code to work efficiently. The journey to future will be surely exciting and truly rewarding in terms of knowledge gain. Stay tuned!!

Click here to read about why and why not we should use VBA.