infotica
vbafaculty@gmail.com
VBA is based on Visual Basic, a programming language derived from BASIC. BASIC stands
for Beginners All-Purpose Symbolic Instruction Code. BASIC is designed to be user-friendly,
because it employs recognizable English words (or quasi-recognizable variations on them)
rather than abstruse and incomprehensible programming terms. In addition to its English-like
diction, BASICs designers endeavored to keep its punctuation and syntax as simple and natural
as possible.
Visual Basic is visual in that it offers drag-and-drop programming techniques and many
graphical elements.
Visual Basic for Applications consists of Visual Basic implementations that share a common
core of objects and commands, but also include application-specific objects and language
elements.
Visual Basic for Applications is a programming language created by Microsoft that can be built
into applications. You use VBA to automate operations in applications that support it. All the
main Office applications Word, Excel, PowerPoint, Outlook, Access, and Project support
VBA, so you can automate operations through most Office applications. In addition,
implementations of VBA can be found in some third-party applications, including Corels
WordPerfect and Autodesks AutoCAD.
VBA allows you to streamline many tasks, avoid burdensome repetition, and improve your
efficiency in many ways.
You can use VBA to automate those repetitive tasks you perform frequently. For example, if the
layout of your monthly report rarely changes, you can use VBA to set up your report each
month.
infotica
vbafaculty@gmail.com
infotica
vbafaculty@gmail.com
Click 'Visual Basic' button in the code group of the developer tab (Alt+F11)
Note : Alt+F11 is also used to switch between Excel and VB-Editor
Macro Security :
infotica
vbafaculty@gmail.com
Recoding a macro:
Starting the Macro Recorder
Start the Macro Recorder by opening the Developer tab on the Ribbon, then clicking the Record
Macro button. Or click the Macro Record button on the status bar at the bottom of the application.
As soon as you start the Macro Recorder, the RecordMacro dialog box opens. You see a default
macro name (Macro1,Macro2, and so on) that you can accept or change. You can add a description
if you wish its optional.
In the Record Macro dialog box, enter a name for the macro youre about to record.
If desired, type a concise but helpful description in the Description box.
This is the Record Macro dialog box for Word.
You can also stop the Macro Recorder by clicking the blue button that appears
on the status bar during recording. Once the Recorder is stopped, the blue button is replaced with
an icon that will start recording a new macro.
Must start with a letter; after that, it can contain both letters and numbers.
Can be up to 255 characters long.
Can contain underscores, which are useful for separating words, such as File Save.
Cannot contain spaces, punctuation, or special characters, such as ! or *.
infotica
vbafaculty@gmail.com
customizations in the Personal Macro Workbook, you can make them available to any
of your procedures.
If the Personal Macro Workbook does not exist yet, the Macro Recorder
creates it automatically.
3. Click OK to start recording the macro.
Do some actions.
To stop recording, click the Stop Recording button (or Stop Recorder, depending on the application),
or click the Stop Recording button on the status bar.
Running a Macro
Press Alt+F8 to display the Macros dialog box, select the macro, and then click the
Run button. (Alternatively, double-click the macro name in the list box.)
Components in VBE :
Project Explorer
displays all open workbooks as vbaprojects.
MS-Excel Objects is the default category that contains all sheets & thisworkbook.
VBA Objects such as Modules, Userforms and Classmodules can be added/removed optionally
Note : Excel Objects can not be added/removed from this window directly
Immediate Window
infotica
vbafaculty@gmail.com
Properties Window
Lists the design-time properties for selected objects and their current settings. You can change these properties at design
time. When you select multiple controls, the Properties window contains a list of the properties common to all the selected
controls.
Window Elements
Object Box
Lists the currently selected object. Only objects from the active form are visible. If you select multiple objects, the
properties common to the objects and their settings, based on the first object selected, appear on the Properties List
tabs.
Properties List Tabs
Alphabetic Tab Alphabetically lists all properties for the selected object that can be changed at design time, as
well as their current settings. You can change the property setting by selecting the property name and typing or
selecting the new setting.
Categorized Tab Lists all properties for the selected object by category. For example, BackColor, Caption,
and ForeColor are in the Appearance category. You can collapse the list so that you see the categories or you
can expand a category to see the properties. When you expand or collapse the list, you see a plus (+) icon or
minus (-) icon to the left of the category name.