P. 1
VBA for Excel Made Simple

VBA for Excel Made Simple

|Views: 620|Likes:
Published by mickaella18

More info:

Published by: mickaella18 on May 29, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/09/2013

pdf

text

original

An Excel/VBA application can be anything from a small task that performs
a useful service to a large application that completely shields the user from
Excel’s basic interface perhaps using a combination of forms and automatic
macros. Excel and VBA provide many features for developers to build
applications that cater for different types of end users. The VBA program-
mer will need to consider who will use the applications and what sort of skills
and experience they have. For example, a novice user – such as a data entry
clerk – may find dialog boxes more helpful than a raw worksheet. This type
of system could well be designed in a foolproof manner. On the other hand,
managers may find an interface that automates the presentation of data –
such as by using charts and graphs – more suitable. Thus, when designing an
appropriate interface with an Excel /VBA application, the following points
should be considered:
M What sort of interface should the application provide? Will it be appropriate
for the end-users? This could turn out to be more complex than it first appears
because users are unlikely to be a simple homogenous group. For example,
some may have very basic knowledge and others may be expert Excel users.
Perhaps some sort of adaptable interface may be appropriate in this situation.
M When a deliverable system contains macros, or user-defined functions, how
w
ill end users know that they exist? How will they find out how to use the
macros? Will the system support these questions with Help, tutorials or
training on how to use the macros provided by the application.
M When a system contains macros how will they run them? Will they:

a) Use Tools > Macro > Macros... from Excel and then select it by name?
b
) Use a button, or customised menu item?
c) Use some other method like a dialog box?
M Is it possible or necessary to provide error checking and validation to help
eliminate mistakes? Is it possible, or desirable, to lock and protect areas that
need to be kept safe on the worksheet?
M Will sufficient on-line context-sensitive Help be available. How will the
end-user know where to find it? Will there be, for example, Help buttons
visible on the worksheets or will messages be supplied by macros?

210

End user interface styles VBA/ Excel applications

In essence, the designer’s decision regarding the interface styles will could
be one of those described below. (Note: A hybrid of two or more of these
styles may be used in practice.)
M The standard Excel worksheet interface may be suitable for those who are
familiar with Excel, supported perhaps with comments to guide the user. For
example, Figure 10.15 illustrates how comments can add explanation to the
meaning of a column of data in a spreadsheet. In the fragment shown of the
weeklysales worksheet of the SALESMAN workbook, the comment elabo-
rates on the meaning of the sales_to_date range. Clearly, the designer of this
type of interface will not require much knowledge of VBA.

Figure 10.15 A raw worksheet interface supported by comments

M A user with an intermediate knowledge of Excel might benefit from the use
of a formatted workbook. That is a workbook using worksheets that have
locked or protected cell ranges, or perhaps use different fonts or colours to
distinguish parts of the system, and so on. Figure 10.15 shows how the
SALESMAN workbook has been formatted to enhance usability. Notice
how the Weekly Sales range of the weeklysales worksheet has been coloured

211

grey to make it stand out. Also, notice that the totals row at the foot of the
data entry area is heavily bordered to make it stand out. An intermediate user
may also benefit from the use of application specific balloon Help.
M A complete Excel novice user might be best served by designing customised
dialog boxes for data entry, or forms with other window controls as a front
end, possibly rendering the worksheet invisible to the user. For example, in
Figure 10.16, a dialog box is used to input data for adding a new representa-
tive into worksheet cells. The design of this system was looked at earlier in
this chapter. For a novice user with no knowledge of spreadsheets this
interface style would be better than using a raw worksheet to add the data.

Figure 10.16 A data entry form suitable for a novice user

212

Exercises

1 Open a new workbook. Go to the VBE and insert a new form. Place on it three
textboxes, with the labels FIRST, SECOND and RESULT, and three buttons
labelled MAXIMUM, MINIMUM and QUIT – the layout should be similar
to that in Figure 10.3. Write event handlers for the buttons. The form should
accept two integers and show in the RESULT either the maximum or
minimum, or quit the program, depending on the button clicked. Check your
program by entering 6 in the FIRST and 15 in the SECOND textbox.
2 Open a new workbook. Write a Workbook.SheetActivate event procedure
that will fill the cells A2, B2 and C2 with the values 1, 2 and 3 respectively
w
henever the user activates a worksheet. Test the results.
3 Study the following code and explain what you think it does:

Private Sub Workbook_NewSheet (ByVal Sh As Object)
Range ("A1:A10").Value = "Month"

End Sub

4 Open a new workbook. Write a Worksheet_Activate event procedure that
will display the message “You have entered Sheet3” whenever Sheet3
becomes the active sheet. Test the procedure.
5 Open the SALESMAN workbook and select the summary worksheet.
Create the form shown in Figure 10.17 and write the event code that will
enable a user to enter a rep name from the rep name list, and enter the highest
and lowest sales in the boxes from the worksheet. If the user enters an invalid
rep name, i.e., one that is not in the list, then the form should be unloaded.
(Hint: You can use the procedure shown on page 137 to find the rep name
from the list and then use the offset method to reference and transfer the
highest and lowest sales to the form.)

Figure 10.17

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->