Cover | Table of Contents | Colophon
ActiveChart.SeriesCollection(1).DataLabels(2).Text = "=MyChartSheet!R12C2"
|
Language
|
General Purpose
|
|---|---|
|
ALGOL
|
An attempt to design a universal language
|
|
BASIC
|
A simple, easy-to-learn language designed for beginners
|
|
C,
C++
|
' Set x equal to 5 x = 5
ProjectName (WorkbookName)
Debug.Print. For instance, the following code will
print whatever text is currently in cell A1 of the active worksheet
to the Immediate window:
Debug.Print ActiveSheet.Range("A1").Text
Sub SubName
Function FunctionName
End
Sub or End
Function statement, or in the general declarations
section). As soon as the Enter key is struck, Excel will move the
line of code to a new location and thereby create a new subroutine.
(It will even add the appropriate ending—End
Sub or End
Function.)
Stop statement in the code, which causes
Excel to enter break mode.
Stop statement, because breakpoints are
automatically removed when we close down the Visual Basic Editor, so
we don't need to remember to remove them, as we do
with Stop statements.
x
==
5 and then attempt to move to another line. Note
that Microsoft refers to this type of error as a compile
error in the dialog box and perhaps we should as well.
However, it seems more descriptive to call it a design-time error or
just a syntax error.
Sub Test() Dim ws As Worksheet Set ws = ActiveSheet ' Insert a value into cell A1 ws.Cells(1, 1).Value = "sample" ' Make it bold ws.Cells(1, 1).Font.Bold = True ' Copy cell ws.Cells(1, 1).Copy ' Paste value only ws.Cells(2, 1).PasteSpecial Paste:=xlValues End Sub
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/13/98 by sr
'
'
Cells.Replace What:="macro", Replacement:="subroutine", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
End Sub' Declare a string variable Dim WksName as String WksName = Activesheet.Name ' Get name of active sheet
ActiveSheet.Range("A1").Font.Bold = _
True' Declare a string variable Dim WksName as String WksName = Activesheet.Name ' Get name of active sheet
ActiveSheet.Range("A1").Font.Bold = _
True"Donna
Smith" and date
constants are enclosed between number signs, as in
#1/1/96#.
Dim dt As Date dt = #1/2/97#
Const keyword, as in:
Const InvoicePath = "d:\Invoices\"
InvoicePath in our code with the string
"d:\Invoices\". Thus,
InvoicePath is a constant, since it never changes
value, but it is not a literal constant, since it is not used as
written.
"d:\Invoices\" to
"d:\OldInvoices\", we only need to change the
definition of InvoicePath to:
Const InvoicePath = "d:\OldInvoices\"
"d:\Invoices\".
Const statement, VBA has a large number of
built-in symbolic constants (about 700), whose names begin with the
lowercase letters vb. Excel VBA adds additional
symbolic constants (1266 of them) that begin with the letters
xl. We will encounter many of these constants
throughout the book.
vbCrLf, which is equivalent to a carriage return
followed by a line feed, and vbTab, which is
equivalent to the tab character.