1.
VBA is a editor to write a macro
2.macro is a object oriented program.
3.it is a piece of code to perform some operation.
how to get developer into the ribbon
_____________________________________
2007
office button->excel options->popular->select "show developer tab" check box->ok
2010/2013
file->options->customize ribbon->select "developer" checkbox->ok
how to open VBA window
________________________
1.developer tab->visual basic
2. ALT+F11
Different Windows in VBA
_________________________
1.Project explorer window
2.Properties window
3 Code window
sheet code window
module code window
class code window
userform code window
4.Object explorer
5.Immediate window
Project explorer window
________________________
It will show all the list of opened projects(list of workbooks) and each project
objects list(sheets,modules,classes,userforms...)
Properties window
__________________
it will show properties of the list of sheets.
According to our requirement we can change the property.
Ex: Name,standardwidth,visible etc
code window
____________
Empty space where we have to write our macro
Sheet code: We can write code in individual sheets.But we can excute(output)
this code only in that particular sheet
How to get sheet code window
__________________________
double click on sheet
Module code:By using this window we can work with different sheets and
workbooks.
How to get module code window
______________________________
insert->module->double click on module
how to rename module
_______________________
single click on module->view->properties window->change name property
class code window:in this window we can create our own classes
class contains methods,properties,events
Ex:Method:Performing action(Sheet add,delete etc)
Property:changing the old value(font color,borders,font size,sheet name etc)
Event:executing a macro when we perform some action(workbook open,close,button
click etc)
How to get class code window
______________________________
insert->class module->double click on module
how to rename class module
_______________________
single click on class->view->properties window->change name property
Userform code window:In this window we will write events to work with
userforms.
How to get userform code window
______________________________
insert->userform
how to rename userform
_______________________
single click on userform->view->properties window->change name property
object browser
___________________
it will show all the list of objects available and its methods,properties and
events
How to see available classes
_______________________________
view->object browser
in the left side it will show all the classes available
in the rights side methods,properties and events of the particular class
Method:green color box
property:hand symbol
event:yellow symbol
Immediate window:
___________________
It will give us immediate results about excel in VBA
Ex:?sheets(1).name
?application.Name
?sheets.Count
Types procedures
_________________
1.sub procedure
2.Function procedure
Sub Procedure:If we want to perform more than one action then we have to write code
in sub procedure
syntax:
sub macro_name()
________
___________
_________
________
end sub
Function procedure:To create our own functions we have to write code in function
procedure
syntax:
function func_name(arguements List)
____________
______________
______________
end function
Argument:
___________
The value which we have to provide to the function as a input to get the output.
Naming Conventions(macro_name/function_name)
____________________________________________
1.Macro name should not start with numbers
2.It will not allow any special characters except underscore(_)
3.Macro name length should not be more than 255
4.It should start with character
Ex: abc(yes)
123abc(no)
abc123(yes)
abc_123(yes)
Identifiers
__________
1.Public(by default)
2.Private
Sample macro
______________
sub test()
msgbox("welcome to macro programming")
end sub
Ways to run a macro
___________________
1.click on play button
2.F5 is the shortcut key
3.assign macro to other objects(Picture,Shapes,controls etc)
4.Developer tab->macros->select macro->click on run button
5.Developer tab->macros->select macro->options->assign shortcut key to your macro
6.F8 line by line exexution(like evaluate formula option)
7.F9 is a break point
How to save the file
_______________________
file->save as->save as type:Excel macro Enabled Workbook->ok
How to enable macros
_____________________
2007/2010/2013
file/office button->options/excel options->trust center->trust center settings-
>macro setting->select enable all macros radio button
or
developer tab->macro security->macro settings->select enable all macros radio
button
cell reference
Comment
__________
To comment the line add single quote(') in the beginning of the line
Comment block/un-comment block
_____________
View->toolbars->customize->select command button->categories:Edit->in commands
section->drag and drop comment block/un-comment block into the ribbon
select block of code->click on comment block
select block of code->click on un-comment block
VBA Editor font
________________