Word Document Properties


BuiltinDocumentProperties



Download 8,82 Mb.
Pdf ko'rish
bet71/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   67   68   69   70   71   72   73   74   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

BuiltinDocumentProperties
in
the Search text field and then click Search. Figure 3-11 shows typical results
for Excel.
Notice the text at the bottom of Figure 3-11. The information includes the full
object name for the property, which comes in handy when you write the code
shown in Listing 3-2. Here’s the code that you need in order to create this
example in Excel. Change the 
ActiveWorkbook
object to the object that
your application supports, such as 
Document
or 
Template
in Word, when
using another application.
Listing 3-2
Getting Author Information from a Document
Public Sub GetSummary()
‘ Declare a DocumentProperty object to hold the
‘ information.
Dim MyProperty As DocumentProperty
‘ Set the DocumentProperty object equal to the author
‘ information.
Set MyProperty = _
Figure 3-11:
The docu-
mentation
often tells
you about
an interest-
ing property
but not
where to
find it.
72
Part II: Learning the Ropes 
08_046500 ch03.qxp 12/5/06 5:34 PM Page 72


ActiveWorkbook.BuiltinDocumentProperties(“Author”)
‘ Display a message box containing the property value.
MsgBox MyProperty.Value, vbOKOnly, “Author Name”
End Sub
This example begins by declaring a variable named 
MyProperty
. However,
MyProperty
is different from other variables because it’s actually an object.
This is a 
DocumentProperty
object that can hold any document property,
including the author or company name.
The next line of code sets 
MyProperty
equal to the author information pro-
vided by the 
BuiltinDocumentProperties(“Author”)
object. You can
set one object equal to another if they’re the same kind of object. It’s like
looking at two apples: You can say that one apple is like another, but you
can’t say that an apple is like an orange. In this case, you’re storing the
author information located in 
MyProperty
in the
BuiltinDocumentProperties(“Author”)
object.
If a line of code is too long, you can continue it on the next line in VBA by
adding an underscore, 
_
, like the one shown in the code example. The under-
score is a 
continuation character.
You should add a continuation character
when the text onscreen requires scrolling. It’s easier to read the code if you
don’t have to scroll from side to side.
The last line of code displays the 
Value
property of the 
MyProperty
object.
VBA already knows how to work with other variables that you have seen. An
object usually requires special handling. In this case, you ask 
MyProperty
what its value is and display it in a message box.
Run this program to see a dialog box containing the name of the document
creator. In most cases, the creator is you. Try changing the Author field entry,
shown in Figure 3-10, to something else. The output of the program changes
to match whatever you type in this field.
Writing Your First Function
The example in the preceding “Writing Your First Sub” section is nice (refer
to Listing 3-2), but you might want more than one piece of information. VBA
users commonly rely on functions to perform repetitive tasks (see the earlier
“Using Functions” section). That’s what the example in this section shows.
Listing 3-3 uses a 
Sub
named 
GetSummary2
to call the 
GetDocProperty
sfunction multiple times. In every case, a special variable stores the result.
At the end of the program, 
GetSummary2
displays all the information that
the program has accumulated.
73

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   67   68   69   70   71   72   73   74   ...   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