VBAS For Engineers Tips Download
VBAS For Engineers Tips Download
P.C.VASANI
Assistant professor
Applied mechanics department
L.D.College of Engineering
Gujarat University
Ahmedabad-380015
(INDIA)
Visual basic application: The new macro language lets one create structured
programs directly in excel.
Dialog box controls directly on worksheet : Excel makes easy to add controls
such as buttons ,list boxes , and option lists to a worksheets requiring little or no
programming.
Custom dialog boxes: One can easily create professional - looking dialog box.
Customizable menus: One can change menu , add to existing menus , or create
entirely new menus.
Customizable short cut menus: Excel is only spreadsheet that lets one customize
the right click, context -sensitive short cut menus.
Slide shows: Create self-running presentation, using text, Charts, pictures and
even sound.
Microsoft Query: One can access important data in standard database file
formats directly from the spreadsheet environment.
Ability to create compiled add-ins : With single command, one can create
uneditable XLA add in files that attach seamlessly.
Customs worksheets functions: Using VBA one can create custom worksheet
functions to simplify formulas and calculations.
2.2 EXCEL AND ITS CONTENTS: Excel elements has object hierarchy. It is clearly
understood that each element of EXCEL can be sub-divided into smaller elements which
is referred as object. EXCEL is a main object. Following are further division of workbook
object.
EXCEL
WORKBOOK
Standard
2.
Formatting
3.
4.
Chart
Manipulating charts
5.
Drawing
6.
Tipwizard
7.
Forms
8.
Stop recording
9.
Visual Basic
10.
Auditing
11.
Workgroup
12.
Microsoft Query
13.
Full screen
VBA does not support custom controls, stored in VBX files. VB. users thrive on
these files, which add lots of new features.
Each VB applications has its own forms design capabilities. The way one designs
form (dialog box) in EXCEL is different from the method used in Project. Both
methods are very different from the way its done in VB.
VBA does not support nearly as many events as VB. In VB., one can attach code
to several events (Button click, Button double click, Button right click,and so on.)
VBA offers two new syntax constructs. In VBA, one can use the For Each.... Next
Control structure for looping through collections (which are essentially groups of
like objects), and With...End With construct for abbreviating object references.
These are not available in VB. Here VBA code can manipulate with all objects of
windows for looping purpose with (For Each Next) and condition statements
with (With End).
Example for each next is as follows;
For each win in Windows
If win.Caption = Bubble chart help Then
Windows ( Bubble chart help).activate
Exit sub
End if
Next win
serves as sort of an object library which must be available in order for the
application to run.
worksheet object can contain objects such as range objects, pivot table objects, and
so on. The arrangement is referred as object model. Like objects form a collection.
For example the worksheet collection consists of all the worksheets in a particular
workbook. The toolbars collection consists of all Toolbar objects. Collections are
objects in themselves. One can refer to an object by specifying its position in the
hierarchy, using a period a separator.
For e.g. workbook can be referred as:Application. Workbooks( Book1 )
This refers to Book1.xls workbook in the workbooks collection is contained in the
application object (that is Excel). Extending this to another level, one can refer to
Sheet1 in Book1 as
Application.Workbooks( Book1 ).worksheets( sheet1 )
One can take it to still another level, and can refer to specific cell as follows:
Application.Workbooks( Book1 ).worksheets( sheet1 ).Range( A1 )
If Book1 is a active workbook, the previous reference can be simplified as
Worksheet( sheet1 ).Range( A1 ). If sheet is active then simply Range(
A1 ).
Object has properties. Range object has properties such as name and value. The
range object can be referred by above property. Suppose a value of a cell is to be
ascertained then can be written as
Worksheets( sheet1 ).Range( A1).Value
Object has methods. Methods can be associated as :Worksheets( sheet1 ).Range( A1 ).Clearcontents.
VBA also supports modern programming languages including arrays, looping ,
and so on.
VBA supports data types for variables such as Boolean, Integer, Long, Single,
Double, Date, String, Object, Variant and user defined.
Dim x as Integer, Dim y as Long ,Dim xyz as Single, Dim abc as Date ,Dim name
as string*20. Dim array size (1 to 20) as single
Besides these user-defined which is similar to C - structures.
2.6.3 PROGRAMMING MODE SUPPORTED BY VBA :
1) GOTO STATEMENTS: This is to continue a process or to skip a
process according to the condition required.
For example
If X > Y GOTO LAST
Msg Box OK
End if
LAST:
:REFERENCES:
1)
2)