Training Material - VBA
Training Material - VBA
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Visual Basic For Application (Excel)
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
What is Macro?
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Creating Macros
There are two methods to create macros
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Adding Developer Tab on Ribbon
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Recording a Macro
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Define the Macro
Macro Name
Short cut
Macro Storage
Description
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Stop Recording
Stop
Recording
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Relative Reference Macro
If you want the macro to run
relative to the position of
the active cell, record it
using relative cell
references. On the
Developer Tab click on Use
Relative Reference so that
it is selected. Excel will
continue to record macros
with relative references until
you quit Excel or until you
click Use Relative
Reference again, so that it is
not selected.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario-1
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Run your Macro
2. The name,
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Run the Macro by the name
1 2
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario– 2
• Create a macro to display a product table with the table headers,
Product Name, Quantity, Price , Total and Net ,
• Table must appear always from the second row and first column,
• Excel should not accept any negative values for price and
quantity.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario – 3
• Create a macro to display the same product table (Scenario2)
but this time it should appear anywhere , where ever user wants
(Using relative reference)
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Creating Buttons on Quick Access ToolBar
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Modifying Menus or Buttons
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario – 4
• Create a macro which will extract region-wise sum of
salary. (Use “Salary worksheet”)
• On click of “Subtotal” button, region-wise subtotal should
be added on a new worksheet.
Click subtotal
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
1. Sort
Continued..
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Continued..
2. Subtotal
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Second Level of Outline
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario– 5
• Create a macro which will extract records from different
department and region.
• User will type the required department and region and click
filter button
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Contd…
Database Range
Criteria Range
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Editing the Recorded Macros
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario– 6
• Open Scenario – 5 and modify the code to do the following
• User should get an InputBox to type the required department
and region and click filter button
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Previous code
Added code
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario– 7
Sales.txt
month,product,Sales in figures Sum of Sales in figures
product month Total
jan,cd,100000 cd jan 100000
feb 75000
jan,Monitor,15000 mar 12000
cd Total 187000
jan,pen drive,75000 Monitor jan 15000
feb 20000
feb,monitor,20000 Monitor Total 35000
feb,Cd,75000 pen drive jan 75000
mar 73000
mar,pen drive,73000 pen drive Total 148000
Grand Total 370000
mar,cd,12000
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
1 2
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
3 4
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario – 8
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Practice - 1
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Practice – 2
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Writing Procedures
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Sub Procedure vs. Function Procedure
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Visual Basic Editor
Project Explorer
Properties Window
Edit Toolbar
Procedure Window
Object Box
Code Window
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Visual Basic Editor
Project Explores Property Window
View Code
View Object
Toggle Folders
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code Window
Object Box Procedure Window
Code
Area
Procedure View
Full Module View
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Inserting Modules
3
1
2
Type new name
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Writing code inside Modules
2
Write your code
here
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Sub Procedure
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Macro
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Function Procedures
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Function Procedure
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 9
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Branching a procedure
If...Then...Endif
If...Then...Else…Endif
If...Then...Elseif…Then…Else…Endif
Select Case …End Select
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 10
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 11
salary grade
<8000 D
8000 – 15000 C
15000 – 25000 B
>=25000 A
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 12
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 13
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 14
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Select Case Vs. If … End If
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Variables and Constants
Variable
• A variable is a named storage location that can contain data that can
be modified during program execution.
• Each variable has a name that uniquely identifies it within its scope.
• A data type can be specified or not.
• Variable names
Must begin with an alphabetic character,
must be unique within the same scope,
can't be longer than 255 characters, and
can't contain an embedded period or type-declaration character.
Constant
• A named item that retains a constant value throughout the execution
of a program. A constant can be a string or numeric literal
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Declaring Variables and Constants
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Data Types of Variables and Constants
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using the Option Explicit Statement
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Message box and Input box
• Msgbox function
Displays a message in a dialog box, waits for the user to click a
button, and returns an Integer indicating which button the user
clicked.
• InputBox Function
Displays a prompt in a dialog box, waits for the user to input
text or click a button, and returns a stringcontaining the
contents of the text box.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Selecting and Activating Cells
• When you work with Microsoft Excel, you usually select a cell
or cells and then perform an action, such as formatting the cells
or entering values in them.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Selecting and Activating rows and columns
• Some times you need to select specific rows and columns and
then perform actions.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Working with Sheets
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Working with WorkBook
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Working with Application
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 15
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 16
• Create a macro name it as Data_Entry
• Accept employee code, name, date of joining and salary of a
person
• Insert the values in “Database” worksheet
• Every new record must be stored after the last record.
Last
Record
New
Record
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using Loops (repeating action)
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using Do...Loop Statements
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Repeating Statements While a Condition is True
You can check the condition before you enter the loop , or
You can check it after the loop has run at least once.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 17
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using For…Next Statements
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 18
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using For Each…Next Statements
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 19
Before After
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 20
Before After
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 21
After
Before
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 22
• Open Scenario – 22 and modify
• After storing record macro should ask to the user to be
continued or not, and run as per user response.
• If user click OK then it should continue the data entry
• If user click Cancel then display Thanks and end the macro.
On OK
On Cancel
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 23
Create a macro which will calculate the following for each employee
• HRA (75% of salary),
• DA (60% of salary) and
• TOTAL (salary +hra +da)
Before
After
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 24
• Create a macro to display list of names of worksheets in current
workbook.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Auto-Executed Macros
To use
Run a macro as soon as workbook Sub auto_open()
gets opened
End Sub
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Practice - 3
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Practice - 4
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 25
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 26
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 27
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
What are Arrays
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Declaring the Arrays
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Using Arrays
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Array Indexing
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Declaring a Dynamic array
• By declaring a dynamic array, you can size the array while the
code is running.
• Use a Dim statement to declare an array, leaving the
parentheses empty
Syntax
Dim Name_Of_Array() As Data_Type
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Resizing a Dynamic Array
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Errors
An error is generated if a statement fails. There are two types of
errors
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Error Handling
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 28
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Error Number
• Each runtime error has a number. If you know the number you
can trap the error by its number.
For example
Error Number Description
61 Disk Full
4 Application defined or
Object defined error
7 Out of memory
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 29
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Debugging the macro
• Debugging is the process of finding and correcting run time
errors and logical errors.
• Press or F8 to execute code one at a time.
Debug Toolbar
Immediate Window
Reset
Step Into Step Out Quick Watch
Run Macro
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
User Forms
• User Forms are used to create customized Dialogue Box as
follows.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Create User Forms
1 2
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Adding other controls
1 3
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Handling events for the control
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario - 30
• Create a UserForm which will accept Participant’s information
to get enrolled for the training.
• Form should have “Insert” and “Cancel” command button .
• When Insert button is clicked the information entered in the
form must go into the excel.
• When Cancel button is clicked the Form should be closed.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
1. Insert a UserForm .
2. Change the name and caption from the property window
Name of the Form USR_enrol
Caption Training Enrolment Form
3. Design the form as follows
Continued...
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Control Name Property Value
Label LBL_header Caption Pragati Software Pvt. Ltd.
Label LBL_name Caption Name
Label LBL_address Caption Address
Label LBL_contactno Caption Contact No.
Label LBL_email Caption Email-id
Label LBL_Subject Caption Subject
TextBox TXT_name
TextBox TXT_address
TextBox TXT_contactno
TextBox TXT_email
TextBox TXT_companyname Text Enter your company name
Frame FRM_details Caption Other Details
Combo Box CBO_subject Caption
Option Button OPT_company Caption Company
Option Button OPT_Personal Caption Personal
Command Button CMD_insert Caption Insert
Command Button CMD_cancel Caption Cancel
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code to give initial values to the control
Continued...
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code for option buttons
Continued...
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code for Insert Button
Sub Enrol_form()
USR_enrol.Show
End Sub
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Add- Ins
• Add- Ins are separate utilities.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Scenario 31
• Create an Add- Ins to convert the case into upper / lower /
proper, according to the option selected by the user.
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Solution
• Design a form for Add-Ins
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Object Name Property Value
Reference Edit Refselect
Option Button Optupper Caption UPPERCASE
Option Button Optlower Caption lowercase
Option Button Optproper Caption Proper Case
Command Button Cmdexit Caption EXIT
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code for the Change Case form
Write your
code here
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code for the Change Case form
Write your
code here
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Code for the Change Case form
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Creating menu through the code
Sub auto_open()
‘This code will create a new menu in the existing menubar , which will have one
‘menuitem i.e., Changecase Add-Ins
Dim newmenu As CommandBarPopup
Dim menuitem As CommandBarButton
Set newmenu = CommandBars(1).Controls.Add(Type:=msoControlPopup,
before:=CommandBars(1).Controls("help").Index)
newmenu.Caption = "E&xtras“
‘When Changecase menuitem is selected it should show changecase form
Set menuitem = newmenu.Controls.Add(Type:=msoControlButton)
menuitem.Caption = "&Change Case"
menuitem.OnAction = "show"
End Sub
Sub auto_close()
‘This will remove menu when add ins is removed from the excel
CommandBars(1).Controls("extras").Delete
End Sub
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Protect your Add-Ins with the password
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Continued…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
How to use Add-Ins
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com
Contd…
Pragati Software Pvt. Ltd., 207, Lok Center, Marol-Maroshi Road, Marol, Andheri (East), Mumbai 400 059. www.pragatisoftware.com