You are on page 1of 7

text string depending on the version. For example, 8.0e or 9.0.

To determine if it is Excel 97 or
Excel 2000, use the following function. It returns an 8 if Excel 97, a 9 if Excel 2000, and most
likely a 10 for the next release of Excel.

Function ExcelVersion() As Integer


ExcelVersion = Val(Application.Version)
End Function

3.4 Protecting Your Code From Others


In Excel access to code modules is now through the Visual Basic Editor (VBE) and projects must
be explicitly password-protected in order for their code to be made unavailable. To hide the code,
go to the VB editor.

 Select Tools, and click on VBA Project Properties.


 Click on the Protection Tab.
 Check Lock Project for viewing and type in your password.

This applies to XLA projects as much as it applies to XLS projects. Unfortunately, a utility is
available that will crack VBA project passwords across Office 97, so, again, this protection only
works against casual users.

If you are concerned that you need more heavyweight protection then you should consider
wrapping your most important code in an ActiveX DLL (most Excel code can be ported pretty
much straight into VB5 or VB6 with a few tweaks to object references) and calling that from a
protected XLA.

3.5 Excel 2000 VBA vs. Excel 97 VBA


Excel 2000 has only a few new features versus Excel 97/2000. There is enhanced web code.
Some VB specific keywords like "Implements", "CallByName" etc. are added. There are some
new objects, properties, methods, and events which are not normally used which were added.

Excel 2000 has a reverse InStr, a routine to split the elements of a delimited string into elements
of an array,. It also has a routine like the worksheet function SUBSTITUTE. There are also
some new features relating to macro security. You have the ability to "sign" your VBA code in
Excel 2000. This allows users with Excel 2000 to automatically accept your code as safe when
they set macro security to High.

There are many cosmetic changes. You can get a complete list of new additions through the help
topic: What's New for Microsoft Excel 2000 Developers In 2000 VBA help

If you don't use any of the new things, your code should run in Excel 97. If you are developing
applications for Excel 97 users, you should do the development in Excel 97 to insure
compatibility.

3.6 Excel Runtime Version

23
A frequently asked question regarding Excel is about the existence of a run-time version of Excel
for users who do not have Excel installed on their machines, but need to run macros or access
data in Excel workbooks. The answer is straight forward: There is not a run-time version of
Excel. Each user must purchase a copy of Excel.

However, you can put your data in Excel workbooks and distribute those files to your audience
even if they don't have Excel. They would have to have the Excel viewer available free from the
Microsoft Web site. They would be able to look at your files, as if they were pictures - they
would not be able to change the values or enter data and run macros.

3.7 Country And Language Versions Of Excel


The xlCountryCode and xlCountrySetting parameters return the LANGUAGE versions of
Excel and Windows, not necessarily the actual country. For example, USA and UK both return
xlCountryCode of 1, even though they are (very) different countries.

Microsoft Excel is published in over 30 languages. You can determine the language version by
using Application.International(xlCountryCode). It returns a number that indicates which
language is in use:

Language Code Country


-------------------------------------------------------------
English 1 The United States of America
Russian 7 Russian Federation
Greek 30 Greece
Dutch 31 The Netherlands
French 33 France
Spanish 34 Spain
Hungarian 36 Hungary
Italian 39 Italy
Czech 42 Czech Republic
Danish 45 Denmark
Swedish 46 Sweden
Norwegian 47 Norway
Polish 48 Poland
German 49 Germany
Portuguese Brazil 55 Brazil
Thai 66 Thailand
Vietnamese 84 Vietnam
Simplified Chinese 86 People's Republic of China
Japanese 81 Japan
Korean 82 South Korea
Turkish 90 Turkey
Indian 91 India
Urdu 92 Pakistan
Portuguese 351 Portugal
Finnish 358 Finland
Traditional Chinese 886 Taiwan
Arabic 966 Saudi Arabia
Hebrew 972 Israel
Farsi 982 Iran

24
For example

Sub LanguageUsed()

Dim sLang As String


Select Case Application.International(xlCountryCode)
Case 1: sLang = "U.S"
Case 34: sLang = "Spanish"
Case Else: sLang = "other"
End Select
MsgBox sLang
End Sub

The following illustrates how to determine if the user is using a US version of Excel.

If Application.International(xlCountryCode)=1 Then
MsgBox "US"
Else
MsgBox "Not US"
End If

The main problem with writing code for other languages typically has been currency. Microsoft
Excel will sometimes default to the U.S. conventions of currency separators with obviously
unsatisfactory results.

3.8 High Security And Enabling Macros


The default setting in Excel 2000 and above is high security. This means that users are not
notified that a file contains macros and are not even given the opportunity to enable macros.
Macros are automatically disabled.

If you want users to enable macros when they open a file, you should have the file open onto a
worksheet with a message saying "If you see this message then you did not enable macros and
they macro features of this workbook are disabled." If the user enables macros, then simply hide
this worksheet as the first command in a subroutine named "Auto_Open".

3.9 How To Determine Regional Settings or Properties


To determine regional Excel settings, use Application.International(index), where index
indicates which setting you want returned. To see a list of the various index values, simply
highlight the keyword International in your code and press the F1 key (or look below).

The following are a few examples:

'decimal separator:

Dim sDecimal As String


sDecimal = Application.International(xlDecimalSeparator)

'Day symbol and a statement that displays the day in a message box

25
Dim sDay As String
sDay = Application.International(xlDayCode)
MsgBox Format(Now(), sDay & sDay & sDay & sDay)

'currency code:

Dim sCurrency As String


sCurrency = Application.International(xlCurrencyCode)

The following are just a few of the index values for International() queries

Index Type Meaning

xlCountryCode Long Country version of Microsoft Excel.

xlCountrySetting Long Current country setting in the Windows Control Panel, or the country
number as determined by your Macintosh system
software.

xlCurrencyCode String Returns the currency character

xlDecimalSeparator String Decimal separator.

xlThousandsSeparator String Zero or thousands separator.

xlListSeparator String List separator.

xlUpperCaseRowLetter String Uppercase row letter (for R1C1-style references).

xlUpperCaseColumnLetter String Uppercase column letter.

xlLowerCaseRowLetter String Lowercase row letter.

xlLowerCaseColumnLetter String Lowercase column letter.

xlLeftBracket String Character used instead of the left bracket ([) in R1C1-style relative
references.

xlRightBracket String Character used instead of the right bracket (]) in R1C1-style references.

xlLeftBrace String Character used instead of the left brace ({) in array literals.

xlRightBrace String Character used instead of the right brace (}) in array literals.

26
xlColumnSeparator String Character used to separate columns in array literals.

xlRowSeparator String Character used to separate rows in array literals.

xlAlternateArraySeparator String Alternate array item separator to use if the current array
separator is the same as the decimal separator.

xlDateSeparator String Date separator (/ in U.S. version).

xlTimeSeparator String Time separator (: in U.S. version).

xlYearCode String Year symbol in number formats (y in U.S. version).

xlMonthCode String Month symbol (m in U.S. version).

xlDayCode String Day symbol (d in U.S. version).

xlHourCode String Hour symbol (h in U.S. version).

xlMinuteCode String Minute symbol (m in U.S. version).

xlSecondCode String Second symbol (s in U.S. version).

xlCurrencyCode String Currency symbol ($ in U.S. version).

xlGeneralFormatName String Name of the General number format.

xlCurrencyDigits Long Number of decimal digits to use in currency formats.

xlCurrencyNegative Long Currency format for negative currency values:

0 = ($x) or (x$)

1 = -$x or -x$

2 = $-x or x-$

3 = $x- or x$-

27
Note that the position of the currency symbol is determined by xlCurrencyBefore.

xlNoncurrencyDigits Long Number of decimal digits to use in non-currency formats.

xlMonthNameChars Long Always returns three for backwards compatibility.

xlWeekdayNameChars Long Always returns three for backwards compatibility.

xlDateOrder Long Order of date elements:

0 = month-day-year

1 = day-month-year

2 = year-month-day

xl24HourClock Boolean True if using 24-hour time, False if using 12-hour time.

xlNonEnglishFunctions Boolean True if not displaying functions in English.

xlMetric Boolean True if using the metric system, False if using the English measurement
system.

xlCurrencySpaceBefore Boolean True if a space is added before the currency symbol.

xlCurrencyBefore Boolean True if the currency symbol precedes the currency values, False if it
follows them.

xlCurrencyMinusSign Boolean True if using a minus sign for negative numbers, False if using
parentheses.

xlCurrencyTrailingZeros Boolean True if trailing zeros are displayed for zero currency values.

xlCurrencyLeadingZeros Boolean True if leading zeros are displayed for zero currency values.

xlMonthLeadingZero Boolean True if a leading zero is displayed in months (when months are
displayed as numbers).

xlDayLeadingZero Boolean True if a leading zero is displayed in days.

28
xl4DigitYears Boolean True if using four-digit years, False if using two-digit years.

xlMDY Boolean True if the date order is month-day-year for dates displayed in the long form,
False if the date order is day-month-year.

xlTimeLeadingZero Boolean True if a leading zero is displayed in times.

3.10 Controlling The Cursor Appearance


The cursor can jiggle back and forth between an hourglass and an arrow as your macros run. It is
possible to control the appearance of the cursor via code. The following sets it to a nice sedate
hourglass:

Application.Cursor = xlWait

To set it back, which you must do before your code completes, use the following statement:

Application.Cursor = xlDefault

If you do not set it back (for example an error occurs that crashes your code), then the cursor will
stay an hourglass.

3.11 Displaying the Developer Tab


In Excel 2007, you can display the developer tab to access macro functions such as
recording a macro by

 Office Button > Excel Optoins > Popular

or

 Press ALT tms

3.12 Using The Immediate Window


The Immediate window in the VB editor is a very useful debug tool. You can use it if you have
paused your macro (either through an error and clicking Debug, using a break point or using a
Stop statement). The Immediate window can be displayed by choosing "Immediate Window"
from the View menu or by pressing CTL-G.

In the immediate window, you can get the a value by typing a question mark and a valid
statement:

?ActiveCell.Value

29

You might also like