Word Document Properties



Download 8,82 Mb.
Pdf ko'rish
bet100/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   96   97   98   99   100   101   102   103   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Listing 4-15
Changing the Format of a Date
Public Sub FormatDemo()
‘ Create the date variable.
Dim MyDate As Date
104
Part II: Learning the Ropes 
09_046500 ch04.qxp 12/5/06 5:54 PM Page 104


‘ Fill MyDate with the current date and time.
MyDate = Now
‘ Display the date using standard formats.
MsgBox “Standard Format =” + vbTab + CStr(MyDate) + _
vbCrLf + “Long Date =” + vbTab + _
Format(MyDate, “Long Date”) + _
vbCrLf + “Short Time =” + vbTab + _
Format(MyDate, “Short Time”), _
vbOKOnly, _
“VBA Named Formats”
End Sub
The program displays the standard date/time format, the long date format,
and the short time format. You get the raw format by using the 
CStr
function.
The 
Format
function requires the 
MyDate
variable and a string containing
the named format as input.
Creating custom formatting
Named formats don’t always provide the output that you need. In these cases,
you can create your own formatting by using custom strings. The elements of
these strings are described in three help topics: User-Defined Date/Time
Formats, User-Defined Numeric Formats, and User-Defined String Formats.
(Press F1 in the VBA IDE to access help.) Listing 4-16 shows how you can
create a custom date-and-time string.
Listing 4-16
Defining a Custom Date Format
Public Sub CustomFormatDemo()
‘ Create the date variable.
Dim MyDate As Date
‘ Fill MyDate with the current date and time.
MyDate = Now
‘ Display the date using standard formats.
MsgBox “Custom Date/Time = “ + _
Format(MyDate, “dd mmmm yyyy Hh:Nn:Ss”), _
vbOKOnly, _
“VBA Custom Formats”
End Sub
The essential difference in this example is the string input for the 
Format
func-
tion. This example tells VBA that you want a date/time display that uses a day
with a leading 0, the full month name, and a four-digit year. The time appears as
hours, minutes, and seconds — all of which have a leading 0 when needed.
105

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   96   97   98   99   100   101   102   103   ...   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