By Steven Roman, Ph.D.
Price: $44.99 USD
£24.95 GBP
Cover | Table of Contents | Colophon
In this chapter:
Program Example: Creating Tables Program Example: Shortcut Key Assignments Program Example: User Interaction Elements of Word VBA Programming
|
Table
| ||
|---|---|---|
|
Border
|
PageSetup
|
Style
|
|
Cell
|
Paragraph
|
Table
|
|
Column
|
ParagraphFormat
|
Template |
In this chapter:
What Is a Programming Language? Programming Style
|
Language
|
General Purpose
|
|---|---|
|
BASIC
|
A simple, easy-to-learn language designed for beginners
|
|
Visual Basic
|
A version of BASIC designed for creating Windows applications
|
|
C, C++
|
Very powerful languages with excellent speed and control over the computer
|
|
Visual C++
|
A version of C++ designed for creating Windows applications
|
|
Pascal
|
' Set x equal to 5 x = 5
In this chapter:
The Project Window The Properties Window The Code Window The Immediate Window Arranging Windows Document Events
ProjectName (DocumentName)
Project (Word)
TemplateProject (CSBOOKS)
Private Sub Document_Open() End Sub
Debug.Print
Debug.Print ActiveWindow.Selection.Range.Text
MsgBox "Template close event fired."
In this chapter:
Navigating the IDE Getting Help Creating a Procedure Run Mode, Design Mode, and Break Mode Errors Debugging Macros
Sub SubName
Function FunctionName
EndSub or EndFunction statement) or in the General window. As soon as you press the Enter key, Word 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 Word to enter break mode.Stop statement, because breakpoints are automatically removed when you close down the Visual Basic Editor, so you don't need to remember to remove them, as you 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.
Dim doc As Document
Set doc = ActiveDocument.Name
Sub test() Dim sent As Range ' Get the third sentence Set sent = ActiveDocument.Range.Sentences(3) ' Select it sent.Select ' Boldface it sent.Bold = True ' Select the first character in the sentence sent.Characters(1).Select ' Change the font Selection.Font.Size = 24 End Sub
Sub AMacro() ' AMacro Macro Macro recorded 04/27/98 by sr ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "macro" .Replacement.Text = "subroutine" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll End Sub
In this chapter:
Comments Line Continuation Constants Variables and Data Types VBA Operators
' Declare a string variable Dim DocName as String DocName = ActiveDocument.Name ' Get name of active doc
ActiveDocument.Paragraphs(1).Alignment = _ wdAlignParagraphCenter
A line-continuation character cannot be inserted in the middle of a literal string constant, which is enclosed in quotation marks.
' Declare a string variable Dim DocName as String DocName = ActiveDocument.Name ' Get name of active doc
ActiveDocument.Paragraphs(1).Alignment = _ wdAlignParagraphCenter
A line-continuation character cannot be inserted in the middle of a literal string constant, which is enclosed in quotation marks.
"Donna Smith"
#1/1/96#
dt:Dim dt As Date dt = #1/2/97#
Const keyword: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.InvoicePath:Const InvoicePath = "d:\OldInvoices\"
Const statement, VBA has a large number of built-in symbolic constants (about 700), whose names begin with the lowercase letters vb. Word VBA adds additional symbolic constants (about 2,000!) that begin with the letters wd. You 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. Also, Word uses vbCr for its paragraph mark.|
Type
|
Size in Memory
|
Range of Values
|
|---|---|---|
|
Byte
|
1 byte
|
0 to 255
|
|
Boolean
|
2 bytes
|
True or False
|
|
Integer
|
2 bytes
|
–32,768 to 32,767
|
|
Long (long integer)
|
4 bytes
|
–2,147,483,648 to 2,147,483,647
|
|
Single (single-precision real)
|
4 bytes
|
Approximately –3.4E38 to 3.4E38
|
|
Double (double-precision real)
|
8 bytes
|
Approximately –1.8E308 to 4.9E324
|
|
Currency (scaled integer)
|
8 bytes
|
Approximately –922,337,203,685,477.5808 to 922,337,203,685,477.5807
|
|
Date
|