Word Document Properties


Part II: Learning the Ropes



Download 8,82 Mb.
Pdf ko'rish
bet112/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   108   109   110   111   112   113   114   115   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Part II: Learning the Ropes 
10_046500 ch05.qxp 12/5/06 5:35 PM Page 122


the 
Select Case
statement. Notice how this statement uses 
Case
clauses
to determine which action to take. You can provide a single value, a range of
values, or a list of values separated as commas. The final step is to place the
Output
value in the worksheet.
Using the Case Else clause

Select Case
statement should normally contain the optional 
Case Else
clause to ensure that you handle all cases, even those that you don’t expect
when you write the program. Adding this clause requires little time and adds
an important error-trapping feature to your program. You could easily change
the program from the previous section to include a 
Select Case
statement
like the one shown in Listing 5-6. (You can find the source code for this exam-
ple on the Dummies.com site at 
http://www.dummies.com/go/vbafd5e
.)
Listing 5-6
Handling Unforeseen Decisions with Case Else
‘ Select a choice of storage room based in the bin.
Select Case BinValue
Case 1
Output = 1
Case 2
Output = 2
Case 3 To 4
Output = 1
Case 5 To 6
Output = 3
Case Else
‘ Tell the user to select only one cell.
MsgBox “Provide a Bin Number between 1 and 6”, _
vbExclamation Or vbOKOnly, _
“Bin Number Input Error”
‘ Exit the Sub without further processing.
End
End Select
The older version of the code could cause problems when you type a non-
existent bin number. This version provides an error message telling you what
range of numbers to use. It exits before the code has a chance to create an
error condition.
123
Chapter 5: Creating Structured Programs
10_046500 ch05.qxp 12/5/06 5:35 PM Page 123


Performing a Task More than
Once by Using Loops
Many tasks that you perform require more than one check, change, or data
manipulation. You don’t change just one entry in a worksheet; you change all
the affected entries. Likewise, you don’t change just one word in a document;
you might change all occurrences based on certain criteria. Databases
require multiple changes for almost any task.
Loops
provide a method for performing tasks more than one time. You can
use loops to save code-writing time. Simply write the code to perform the
repetitive task once and then tell VBA to perform the task multiple times.
When using loops, you decide how the code determines when to stop. You
can tell the loop to execute a specific number of times or to continue execut-
ing until the program meets a certain condition.
Using the Do While...Loop statement

Do While...Loop
statement keeps performing a task until a certain con-
dition is true. The loop checks the expression first and then executes the
code within the structure if the expression is true. You use this loop to per-
form processing zero or more times. A 
Do While...Loop
works especially
well if you can’t determine the number of times that the loop should execute
when you design your program.
One example of a file that could require zero or more changes is a Word docu-
ment. You might need to format certain words in a specific way for each file,
but you have no idea which words you’ll use or whether you’ll use them at
all. The code in Listing 5-7 shows a technique for checking specific words and
formatting them. You could easily adapt this program to meet your format-
ting needs. (You can find the source code for this example on the
Dummies.com site at 
http://www.dummies.com/go/vbafd5e
.)

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   108   109   110   111   112   113   114   115   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish