Word Document Properties


Chapter 7: Interacting with the User



Download 8,82 Mb.
Pdf ko'rish
bet142/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   138   139   140   141   142   143   144   145   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 7: Interacting with the User
12_046500 ch07.qxp 12/5/06 5:35 PM Page 163


Listing 7-2
Using the Clipboard to Copy Data
Private Sub btnCopy_Click()
‘ Create a Clipboard storage object.
Dim ClipData As DataObject
Set ClipData = New DataObject
‘ Place the text in lblOutput in the Clipboard.
ClipData.SetText lblOutput.Caption
‘ Place the object on the Clipboard.
ClipData.PutInClipboard
End Sub
Private Sub btnQuit_Click()
‘End the program.
End
End Sub
Private Sub btnTest_Click()
‘ Create a string to hold the data.
Dim Output As String
‘ Create a document property holder.
Dim DocProp As DocumentProperty
‘ Handle properties that the application doesn’t
support.
On Error Resume Next
‘ Start creating the output string.
For Each DocProp In _
ActiveWorkbook.BuiltinDocumentProperties
Output = Output + DocProp.Name + “ = “ + _
CStr(DocProp.Value) + vbCrLf
Next
‘ Display the output onscreen.
lblOutput.Caption = Output
‘ Enable the Copy Data button.
btnCopy.Enabled = TrueEnd
Sub
VBA puts your code in alphabetical order when you work with forms, which
changes the appearance of the code, but not the actual flow. This technique
makes it easier to find a particular 
Sub
. However, it can also make it more 
difficult to follow the expected flow of the program. The code begins with
btnTest_Click
because 
btnCopy
is disabled when you start the program.
The “Writing Your First Sub” section of Chapter 3 shows how to retrieve just
one value from the 
BuiltinDocumentProperties
collection. This example
164
Part II: Learning the Ropes 
12_046500 ch07.qxp 12/5/06 5:35 PM Page 164


shows how to use the 
For Each...Next
statement to retrieve all the values
available for an application.
Notice that 
btnTest_Click
uses the 
On Error Resume Next
statement.
This program shows one of the few times where that statement is the correct
one to use. Not every application supports every built-in property. If you try
to retrieve the value of a built-in property that the application doesn’t sup-
port, VBA generates an error. Because there’s nothing that you should do 
to correct the error, resuming with the next statement is the correct error-
handling strategy.
After the code retrieves all the built-in document properties, it places the
information in the 
lblOutput.Caption
property, which displays the infor-
mation onscreen. The code also enables 
btnCopy
by setting its 
Enabled
property to true.
The 
btnCopy_Click
sub-procedure introduces the 
DataObject
type. You
might need to interact with the Clipboard when writing an application. This
object is what you use to perform the interaction. The 
DataObject
methods
help you retrieve information from the Clipboard, place information on the
Clipboard, and format Clipboard data.
Working with the Clipboard is normally a two-step process. To place data on
the Clipboard, the code must place it in the 
DataObject
first by using the
SetText
method. The next step uses the 
PutInClipboard
method to 
move the data from the 
DataObject
to the Clipboard. To get data from
the Clipboard, follow the opposite procedure. Use the 
GetFromClipboard
method to place the text on the Clipboard into the 
DataObject
and then use
the 
GetText
method to move the data from the 
DataObject
to a variable.
Every program that you create should include some means of ending. A
dialog-box–based program, like the one in this section, normally includes a
Quit or an Exit button. A configuration dialog box normally relies on the OK
or Cancel button to perform cleanup and then exit. The 
btnQuit_Click
sub-procedure for this example performs a simple task — it uses the 
End
statement to end the program.
Saying yes or no with check 
boxes and toggle buttons
The 
CheckBox
and 
ToggleButton
controls are Boolean — controls with a
true or false value. The implication of each control is different. A 
CheckBox
control normally indicates yes or no. On the other hand, a 
ToggleButton
control indicates an on or off condition. You can use the controls as you see
fit, but this is the normal way to work with them.
165

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   138   139   140   141   142   143   144   145   ...   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