Presentation is loading. Please wait.

Presentation is loading. Please wait.

Developing an Excel Applications

Similar presentations


Presentation on theme: "Developing an Excel Applications"— Presentation transcript:

1 Developing an Excel Applications
By Prof. H-M. Haav

2 For creating an application one needs
Macros Modules Controls

3 Macros can be created in two ways:
Recording plan actions you need to automate Tools>Record a new macro perform actions you need to automate stop recording Writing macros in VBA Tools>macros

4 Visual Basic for Applications VBA
1. Structure of Procedure (module) Sub name_of_program (parameters,…) <statements> ….. End sub

5 2. Reading data from active sheet
variable = cell (reading one value) S = S=Range(“A1”) S=Range (“Start”) S=Cells(1,1) Cells(row index, column index) returns value of specified cell

6 2. Writing data to active sheet
range = expression Cells(1,1) = 5 Range(“A1”) = “last name” Range (“Start”) = “last name” Cells(1,2) = SUM (B1:B7)

7 Naming ranges is useful for creating programs in VBA
Sheets(“Sheet name”).Range(“Start”)

8 4. Dialog Boxes allow dialog with end-user of an application
Sub computer (optional Year) Year =InputBox(“Input year of craetion of the first PC”) If Year = 1976 Then msg=“True!” Else msg=“False!” MsgBox msg End Sub

9 Objects and classes in Excel
Application Command bars dialog Workbook(s) chart windows Chart objects Worksheet(s) Shape(s) Range

10 References to objects Workbooks(“BananaMadness.xls”)
Worksheets(“Title Sheet”) Sheets(1) ActiveWorkbook.Sheets(3) Rows(3) Columns(1) Range(“Starts”).Cells (all cells in the range)

11 Properties of objects Object.[property] x=Range(“Starts”).value
assigns variable x a value of range called Starts .ActiveSheet .ActiveCell .Selection Range(“Starts”).CurrentRegion …etc

12 Methods of objects Object.method[arguments]
Worksheet(“Title Sheet”).Select Worksheet(“Title Sheet”).Activate Worksheet(“Title Sheet”).Calculate Worksheet(“Title Sheet”).Delete Range(“Starts”).Clear …etc

13 Controls Button Radio button Combo box To create a control
turn on Forms toolbar select the control drag the control to needed area define properties

14 Assign macro to a control
select the control on Tools menu, click Assign Macro enter or choose the name of your existing macro

15 Examples of recorded macros
Sub TotalBonus() Range("I7").Select ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])" Selection.AutoFill Destination:=Range("I7:I10"), Type:=xlFillDefault Range("I7:I10").Select Selection.Style = "Currency" End Sub


Download ppt "Developing an Excel Applications"

Similar presentations


Ads by Google