Microsoft Office Tutorials and References
In Depth Information
Covering the Basics of VBA
Is VBA becoming obsolete?
For the past few years, I’ve heard rumors that Microsoft is going to remove VBA from the Office
applications and replace it with .NET. My understanding is that these rumors are completely
unfounded. Sure, Microsoft has developed another way to automate Office applications, but
VBA will be around for quite a while — at least in Excel for Windows. Microsoft has removed
VBA from Excel for Macintosh, but that was no great loss because most Excel VBA apps don’t
even attempt to be compatible with the Mac version.
Why will VBA survive? Because literally millions of VBA-based solutions are in use and VBA is
much easier to learn and use than the alternative.
Covering the Basics of VBA
Before I get into the meat of things, I suggest that you read through the material in this section
to get a broad overview of where I’m heading. I cover these topics in the remainder of this
chapter.
Following is a quick-and-dirty summary of what VBA is all about:
h Code: You perform actions in VBA by executing VBA code. You write (or record) VBA
code, which is stored in a VBA module.
h Module: VBA modules are stored in an Excel workbook file, but you view or edit a
module by using the Visual Basic Editor (VBE). A VBA module consists of procedures.
h Procedures: A procedure is basically a unit of computer code that performs some action.
VBA supports two types of procedures: Sub procedures and Function procedures.
Sub : A Sub procedure consists of a series of statements and can be executed in a
number of ways. Here’s an example of a simple Sub procedure called Test : This
procedure calculates a simple sum and then displays the result in a message box.
Sub Test()
Sum = 1 + 1
MsgBox “The answer is “ & Sum
End Sub
Function : A VBA module can also have Function procedures. A Function
procedure returns a single value (or possibly an array). A Function can be called from
another VBA procedure or used in a worksheet formula. Here’s an example of a
Function named AddTwo :
Function AddTwo(arg1, arg2)
AddTwo = arg1 + arg2
End Function
 
Search JabSto ::




Custom Search