Discussion:
簡轉繁vba
(时间太久无法回复)
ªá¥Ò¯Î
2008-09-05 11:29:53 UTC
Permalink
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curtime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Public Function zhuanhua(curtime As Variant, id As Integer)
'ÐÇÆÚÃû
WeekName(0) = " * "
WeekName(1) = "ÐÇÆÚÈÕ"
WeekName(2) = "ÐÇÆÚÒ»"
WeekName(3) = "ÐÇÆÚ¶þ"
WeekName(4) = "ÐÇÆÚÈý"
WeekName(5) = "ÐÇÆÚËÄ"
WeekName(6) = "ÐÇÆÚÎå"
WeekName(7) = "ÐÇÆÚÁù"
'ÌìžÉÃû³Æ
TianGan(0) = "Œ×"
TianGan(1) = "ÒÒ"
TianGan(2) = "±û"
TianGan(3) = "¶¡"
TianGan(4) = "Îì"
TianGan(5) = "μ"
TianGan(6) = "žý"
TianGan(7) = "ÐÁ"
TianGan(8) = "ÈÉ"
TianGan(9) = "¹ï"
'µØÖ§Ãû³Æ
DiZhi(0) = "×Ó"
DiZhi(1) = "³ó"
DiZhi(2) = "Òú"
DiZhi(3) = "î"
DiZhi(4) = "³œ"
DiZhi(5) = "ËÈ"
DiZhi(6) = "Îç"
DiZhi(7) = "ÎŽ"
DiZhi(8) = "Éê"
DiZhi(9) = "ÓÏ"
DiZhi(10) = "Ðç"
DiZhi(11) = "º¥"
'ÊôÏàÃû³Æ
ShuXiang(0) = "Êó"
ShuXiang(1) = "Å£"
ShuXiang(2) = "Ȣ"
ShuXiang(3) = "ÍÃ"
ShuXiang(4) = "Áú"
ShuXiang(5) = "Éß"
ShuXiang(6) = "Âí"
ShuXiang(7) = "Ñò"
ShuXiang(8) = "ºï"
ShuXiang(9) = "ŒŠ"
ShuXiang(10) = "¹·"
ShuXiang(11) = "Öí"
'Å©ÀúÈÕÆÚÃû
DayName(0) = "*"
DayName(1) = "³õÒ»"
DayName(2) = "³õ¶þ"
DayName(3) = "³õÈý"
DayName(4) = "³õËÄ"
DayName(5) = "³õÎå"
DayName(6) = "³õÁù"
DayName(7) = "³õÆß"
DayName(8) = "³õ°Ë"
DayName(9) = "³õŸÅ"
DayName(10) = "³õÊ®"
DayName(11) = "ʮһ"
DayName(12) = "Ê®¶þ"
DayName(13) = "Ê®Èý"
DayName(14) = "Ê®ËÄ"
DayName(15) = "Ê®Îå"
DayName(16) = "Ê®Áù"
DayName(17) = "Ê®Æß"
DayName(18) = "Ê®°Ë"
DayName(19) = "Ê®ŸÅ"
DayName(20) = "¶þÊ®"
DayName(21) = "Ø¥Ò»"
DayName(22) = "Ø¥¶þ"
DayName(23) = "Ø¥Èý"
DayName(24) = "Ø¥ËÄ"
DayName(25) = "Ø¥Îå"
DayName(26) = "Ø¥Áù"
DayName(27) = "Ø¥Æß"
DayName(28) = "Ø¥°Ë"
DayName(29) = "Ø¥ŸÅ"
DayName(30) = "ÈýÊ®"
'Å©ÀúÔ·ÝÃû
MonName(0) = "*"
MonName(1) = "Õý"
MonName(2) = "¶þ"
MonName(3) = "Èý"
MonName(4) = "ËÄ"
MonName(5) = "Îå"
MonName(6) = "Áù"
MonName(7) = "Æß"
MonName(8) = "°Ë"
MonName(9) = "ŸÅ"
MonName(10) = "Ê®"
MonName(11) = "ʮһ"
MonName(12) = "À°"
'¹«ÀúÿÔÂÇ°ÃæµÄÌìÊý
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'Å©ÀúÊýŸÝ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'Éú³Éµ±Ç°¹«ÀúÄê¡¢Ô¡¢ÈÕ ==> GongliStr
curYear = Year(curtime)
curMonth = Month(curtime)
curDay = Day(curtime)
GongliStr = curYear & "Äê"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ÔÂ"
Else
GongliStr = GongliStr & curMonth & "ÔÂ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ÈÕ"
Else
GongliStr = GongliStr & curDay & "ÈÕ"
End If
'Éú³Éµ±Ç°¹«ÀúÐÇÆÚ ==> WeekdayStr
curWeekday = Weekday(curtime)
WeekdayStr = WeekName(curWeekday)
'ŒÆË㵜³õʌʱŒä1921Äê2ÔÂ8ÈÕµÄÌìÊý£º1921-2-8(ÕýÔ³õÒ»)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
zhuanhua1 = GongliStr & WeekdayStr
'ŒÆËãÅ©ÀúÌìžÉ?µØÖ§?ÔÂ?ÈÕ
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'»ñÈ¡NongliData(m)µÄµÚnžö¶þœøÖÆλµÄÖµ
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If
'Éú³ÉÅ©ÀúÌìžÉ¡¢µØÖ§¡¢ÊôÏà ==> NongliStr
NongliStr = "Å©Àú" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "Äê"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) &
")"
'Éú³ÉÅ©ÀúÔ¡¢ÈÕ ==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "Èò" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "ÔÂ"
NongliDayStr = NongliDayStr & DayName(curDay)
zhuanhua2 = NongliStr & NongliDayStr
If id <> 0 Then
zhuanhua = zhuanhua1
Else
zhuanhua = zhuanhua2
End If
End Function

šçŒÆµ²ªGšÒŠp:5/9/2008 ??¥³€lŠ~(¹«)€K€ëªì€»


€W­±¬O²Å骺ŠÛ­qšçŒÆœX,Š]¬°¬O²ÅéœX,©Ò¥HŠ³šÇ¹qž£šÏ¥Î®É¥X²{¶ÃœX,Š³œÖ¯à§ï¬°ÁcÅ骩?©Î«çŒËšÏ€§¯à¥Î? 2007€]¬O¶ÃœX°Ú! ÁÂ!
天道無常
2008-09-06 00:25:38 UTC
Permalink
我將原先的 "curTime = Now()" 改過,換成 ActiveCell.Value.

---------------------------
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'獲取當前系統時間
'curTime = Now()

curTime = ActiveCell.Value


'星期名
WeekName(0) = " * "
WeekName(1) = "星期日"
WeekName(2) = "星期一"
WeekName(3) = "星期二"
WeekName(4) = "星期三"
WeekName(5) = "星期四"
WeekName(6) = "星期五"
WeekName(7) = "星期六"
'天干名稱
TianGan(0) = "甲"
TianGan(1) = "乙"
TianGan(2) = "丙"
TianGan(3) = "丁"
TianGan(4) = "戊"
TianGan(5) = "己"
TianGan(6) = "庚"
TianGan(7) = "辛"
TianGan(8) = "壬"
TianGan(9) = "癸"
'地支名稱
DiZhi(0) = "子"
DiZhi(1) = "丑"
DiZhi(2) = "寅"
DiZhi(3) = "卯"
DiZhi(4) = "辰"
DiZhi(5) = "巳"
DiZhi(6) = "午"
DiZhi(7) = "未"
DiZhi(8) = "申"
DiZhi(9) = "酉"
DiZhi(10) = "戌"
DiZhi(11) = "亥"
'屬相名稱
ShuXiang(0) = "鼠"
ShuXiang(1) = "牛"
ShuXiang(2) = "虎"
ShuXiang(3) = "兔"
ShuXiang(4) = "龍"
ShuXiang(5) = "蛇"
ShuXiang(6) = "馬"
ShuXiang(7) = "羊"
ShuXiang(8) = "猴"
ShuXiang(9) = "雞"
ShuXiang(10) = "狗"
ShuXiang(11) = "豬"
'農曆日期名
DayName(0) = "*"
DayName(1) = "初一"
DayName(2) = "初二"
DayName(3) = "初三"
DayName(4) = "初四"
DayName(5) = "初五"
DayName(6) = "初六"
DayName(7) = "初七"
DayName(8) = "初八"
DayName(9) = "初九"
DayName(10) = "初十"
DayName(11) = "十一"
DayName(12) = "十二"
DayName(13) = "十三"
DayName(14) = "十四"
DayName(15) = "十五"
DayName(16) = "十六"
DayName(17) = "十七"
DayName(18) = "十八"
DayName(19) = "十九"
DayName(20) = "二十"
DayName(21) = "廿一"
DayName(22) = "廿二"
DayName(23) = "廿三"
DayName(24) = "廿四"
DayName(25) = "廿五"
DayName(26) = "廿六"
DayName(27) = "廿七"
DayName(28) = "廿八"
DayName(29) = "廿九"
DayName(30) = "三十"
'農曆月份名
MonName(0) = "*"
MonName(1) = "正"
MonName(2) = "二"
MonName(3) = "三"
MonName(4) = "四"
MonName(5) = "五"
MonName(6) = "六"
MonName(7) = "七"
MonName(8) = "八"
MonName(9) = "九"
MonName(10) = "十"
MonName(11) = "十一"
MonName(12) = "臘"
'公曆每月前面的天數
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'農曆數據
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'生成當前公曆年、月、日==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "年"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "月"
Else
GongliStr = GongliStr & curMonth & "月"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "日"
Else
GongliStr = GongliStr & curDay & "日"
End If
'生成當前公曆星期==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
'計算到初始時間1921年2月8日的天數:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'計算農曆天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'獲取NongliData(m)的第n個二進制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '生成農曆天干、地支、屬相==> NongliStr
NongliStr = "農曆" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'生成農曆月、日==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "閏" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "月"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
ªá¥Ò¯Î
2008-09-06 11:05:10 UTC
Permalink
Attribute
¹qž£»¡»yªk¿ù. «ç»ò¿ì?
§Ú€£ÀŽªºœÐ«ü±Ð
§Ú±N­ì¥ýªº "curTime = Now()" §ï¹L¡AŽ«Šš ActiveCell.Value¡D
¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '¥ÍŠš¹AŸä€Ñ€z¡BŠa€ä¡BÄݬÛ==> NongliStr
NongliStr = "¹AŸä" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "Š~"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'¥ÍŠš¹AŸä€ë¡B€é==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "¶|" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "ۑ"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
天道無常
2008-09-06 12:13:47 UTC
Permalink
我在我的Excel 2003上試過,沒問題.能否列出完整的錯誤訊息?

你若是直接將下文剪貼到Excel的VBA editor中,會有問題,因為有的程式碼很
長,而討論版有寬度限制,太長的會分成兩行.若是貼到Excel VBA editor後,呈
現紅字,那可能是一行被分成兩行,得自己將它合併成一行.

喔!"Attribute VB_Name = "Module1""這一行要刪去,不要貼到Excel中.那是我
將程式輸出為.bas檔時,Excel自己加了那一行.我貼文時,一時不察,忘了將那
一行刪去.抱歉!
Post by 天道無常
Attribute
電腦說語法錯. 怎麼辦?
我不懂的請指教
Post by 天道無常
我將原先的 "curTime = Now()" 改過,換成 ActiveCell.Value.
---------------------------
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'獲取當前系統時間
'curTime = Now()
curTime = ActiveCell.Value
'星期名
WeekName(0) = " * "
WeekName(1) = "星期日"
WeekName(2) = "星期一"
WeekName(3) = "星期二"
WeekName(4) = "星期三"
WeekName(5) = "星期四"
WeekName(6) = "星期五"
WeekName(7) = "星期六"
'天干名稱
TianGan(0) = "甲"
TianGan(1) = "乙"
TianGan(2) = "丙"
TianGan(3) = "丁"
TianGan(4) = "戊"
TianGan(5) = "己"
TianGan(6) = "庚"
TianGan(7) = "辛"
TianGan(8) = "壬"
TianGan(9) = "癸"
'地支名稱
DiZhi(0) = "子"
DiZhi(1) = "丑"
DiZhi(2) = "寅"
DiZhi(3) = "卯"
DiZhi(4) = "辰"
DiZhi(5) = "巳"
DiZhi(6) = "午"
DiZhi(7) = "未"
DiZhi(8) = "申"
DiZhi(9) = "酉"
DiZhi(10) = "戌"
DiZhi(11) = "亥"
'屬相名稱
ShuXiang(0) = "鼠"
ShuXiang(1) = "牛"
ShuXiang(2) = "虎"
ShuXiang(3) = "兔"
ShuXiang(4) = "龍"
ShuXiang(5) = "蛇"
ShuXiang(6) = "馬"
ShuXiang(7) = "羊"
ShuXiang(8) = "猴"
ShuXiang(9) = "雞"
ShuXiang(10) = "狗"
ShuXiang(11) = "豬"
'農曆日期名
DayName(0) = "*"
DayName(1) = "初一"
DayName(2) = "初二"
DayName(3) = "初三"
DayName(4) = "初四"
DayName(5) = "初五"
DayName(6) = "初六"
DayName(7) = "初七"
DayName(8) = "初八"
DayName(9) = "初九"
DayName(10) = "初十"
DayName(11) = "十一"
DayName(12) = "十二"
DayName(13) = "十三"
DayName(14) = "十四"
DayName(15) = "十五"
DayName(16) = "十六"
DayName(17) = "十七"
DayName(18) = "十八"
DayName(19) = "十九"
DayName(20) = "二十"
DayName(21) = "廿一"
DayName(22) = "廿二"
DayName(23) = "廿三"
DayName(24) = "廿四"
DayName(25) = "廿五"
DayName(26) = "廿六"
DayName(27) = "廿七"
DayName(28) = "廿八"
DayName(29) = "廿九"
DayName(30) = "三十"
'農曆月份名
MonName(0) = "*"
MonName(1) = "正"
MonName(2) = "二"
MonName(3) = "三"
MonName(4) = "四"
MonName(5) = "五"
MonName(6) = "六"
MonName(7) = "七"
MonName(8) = "八"
MonName(9) = "九"
MonName(10) = "十"
MonName(11) = "十一"
MonName(12) = "臘"
'公曆每月前面的天數
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'農曆數據
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'生成當前公曆年、月、日==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "年"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "月"
Else
GongliStr = GongliStr & curMonth & "月"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "日"
Else
GongliStr = GongliStr & curDay & "日"
End If
'生成當前公曆星期==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
'計算到初始時間1921年2月8日的天數:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'計算農曆天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'獲取NongliData(m)的第n個二進制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '生成農曆天干、地支、屬相==> NongliStr
NongliStr = "農曆" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'生成農曆月、日==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "閏" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "月"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
ªá¥Ò¯Î
2008-09-06 12:56:34 UTC
Permalink
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
§ÚŠb§ÚªºExcel 2003€WžÕ¹L¡AšS°ÝÃD¡D¯à§_ŠC¥X§¹Ÿãªº¿ù»~°T®§¡H
§A­Y¬Oªœ±µ±N€U€å°Å¶KšìExcelªºVBA editor€€¡A·|Š³°ÝÃD¡AŠ]¬°Š³ªºµ{Š¡œX«Ü
ªø¡AŠÓ°Qœ×ª©Š³Œe«×­­šî¡A€Óªøªº·|€ÀŠššâŠæ¡D­Y¬O¶KšìExcel VBA editor«á¡A§e
Post by 天道無常
Attribute
¹qž£»¡»yªk¿ù. «ç»ò¿ì?
§Ú€£ÀŽªºœÐ«ü±Ð
§Ú±N­ì¥ýªº "curTime = Now()" §ï¹L¡AŽ«Šš ActiveCell.Value¡D
¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '¥ÍŠš¹AŸä€Ñ€z¡BŠa€ä¡BÄݬÛ==> NongliStr
NongliStr = "¹AŸä" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "Š~"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'¥ÍŠš¹AŸä€ë¡B€é==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "¶|" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "ۑ"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
chijanzen
2008-09-06 13:10:03 UTC
Permalink
你好:

你也可以參考我之前做的農曆年函數,有使用的方法介紹

http://chijanzen.net/wp/?p=45

還有你也可以下載 VBA 程式碼 繁簡轉換工具,自己可以轉換

http://chijanzen.net/wp/?p=177
--
天行健,君子以自強不息
地勢坤,君子以厚德載物

http://chijanzen.net
Post by ªá¥Ò¯Î
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
這是一行嗎?
我做成一行了,但函數出錯誤值#name?
Post by 天道無常
我在我的Excel 2003上試過,沒問題.能否列出完整的錯誤訊息?
你若是直接將下文剪貼到Excel的VBA editor中,會有問題,因為有的程式碼很
長,而討論版有寬度限制,太長的會分成兩行.若是貼到Excel VBA editor後,呈
現紅字,那可能是一行被分成兩行,得自己將它合併成一行.
喔!"Attribute VB_Name = "Module1""這一行要刪去,不要貼到Excel中.那是我
將程式輸出為.bas檔時,Excel自己加了那一行.我貼文時,一時不察,忘了將那
一行刪去.抱歉!
Post by 天道無常
Attribute
電腦說語法錯. 怎麼辦?
我不懂的請指教
Post by 天道無常
我將原先的 "curTime = Now()" 改過,換成 ActiveCell.Value.
---------------------------
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'獲取當前系統時間
'curTime = Now()
curTime = ActiveCell.Value
'星期名
WeekName(0) = " * "
WeekName(1) = "星期日"
WeekName(2) = "星期一"
WeekName(3) = "星期二"
WeekName(4) = "星期三"
WeekName(5) = "星期四"
WeekName(6) = "星期五"
WeekName(7) = "星期六"
'天干名稱
TianGan(0) = "甲"
TianGan(1) = "乙"
TianGan(2) = "丙"
TianGan(3) = "丁"
TianGan(4) = "戊"
TianGan(5) = "己"
TianGan(6) = "庚"
TianGan(7) = "辛"
TianGan(8) = "壬"
TianGan(9) = "癸"
'地支名稱
DiZhi(0) = "子"
DiZhi(1) = "丑"
DiZhi(2) = "寅"
DiZhi(3) = "卯"
DiZhi(4) = "辰"
DiZhi(5) = "巳"
DiZhi(6) = "午"
DiZhi(7) = "未"
DiZhi(8) = "申"
DiZhi(9) = "酉"
DiZhi(10) = "戌"
DiZhi(11) = "亥"
'屬相名稱
ShuXiang(0) = "鼠"
ShuXiang(1) = "牛"
ShuXiang(2) = "虎"
ShuXiang(3) = "兔"
ShuXiang(4) = "龍"
ShuXiang(5) = "蛇"
ShuXiang(6) = "馬"
ShuXiang(7) = "羊"
ShuXiang(8) = "猴"
ShuXiang(9) = "雞"
ShuXiang(10) = "狗"
ShuXiang(11) = "豬"
'農曆日期名
DayName(0) = "*"
DayName(1) = "初一"
DayName(2) = "初二"
DayName(3) = "初三"
DayName(4) = "初四"
DayName(5) = "初五"
DayName(6) = "初六"
DayName(7) = "初七"
DayName(8) = "初八"
DayName(9) = "初九"
DayName(10) = "初十"
DayName(11) = "十一"
DayName(12) = "十二"
DayName(13) = "十三"
DayName(14) = "十四"
DayName(15) = "十五"
DayName(16) = "十六"
DayName(17) = "十七"
DayName(18) = "十八"
DayName(19) = "十九"
DayName(20) = "二十"
DayName(21) = "廿一"
DayName(22) = "廿二"
DayName(23) = "廿三"
DayName(24) = "廿四"
DayName(25) = "廿五"
DayName(26) = "廿六"
DayName(27) = "廿七"
DayName(28) = "廿八"
DayName(29) = "廿九"
DayName(30) = "三十"
'農曆月份名
MonName(0) = "*"
MonName(1) = "正"
MonName(2) = "二"
MonName(3) = "三"
MonName(4) = "四"
MonName(5) = "五"
MonName(6) = "六"
MonName(7) = "七"
MonName(8) = "八"
MonName(9) = "九"
MonName(10) = "十"
MonName(11) = "十一"
MonName(12) = "臘"
'公曆每月前面的天數
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'農曆數據
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'生成當前公曆年、月、日==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "年"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "月"
Else
GongliStr = GongliStr & curMonth & "月"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "日"
Else
GongliStr = GongliStr & curDay & "日"
End If
'生成當前公曆星期==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
'計算到初始時間1921年2月8日的天數:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'計算農曆天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'獲取NongliData(m)的第n個二進制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
ªá¥Ò¯Î
2008-09-06 13:32:14 UTC
Permalink
·PÁ§A!
Šý§Ú¬OžÕ­nŸÇ¥Î
§A€]¥i¥H°ÑŠÒ§Ú€§«e°µªº¹AŸäŠ~šçŒÆ¡AŠ³šÏ¥Îªº€èªk€¶²Ð
http://chijanzen.net/wp/?p=45
ÁÙŠ³§A€]¥i¥H€Užü VBA µ{Š¡œX Ác²ÂàŽ«€ušã¡AŠÛ€v¥i¥HÂàŽ«
http://chijanzen.net/wp/?p=177
--
€ÑŠæ°·¡A§g€l¥HŠÛ±j€£®§
Ša¶Õ©[¡A§g€l¥H«pŒwžüª«
http://chijanzen.net
Post by ªá¥Ò¯Î
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
§ÚŠb§ÚªºExcel 2003€WžÕ¹L¡AšS°ÝÃD¡D¯à§_ŠC¥X§¹Ÿãªº¿ù»~°T®§¡H
§A­Y¬Oªœ±µ±N€U€å°Å¶KšìExcelªºVBA editor€€¡A·|Š³°ÝÃD¡AŠ]¬°Š³ªºµ{Š¡œX«Ü
ªø¡AŠÓ°Qœ×ª©Š³Œe«×­­šî¡A€Óªøªº·|€ÀŠššâŠæ¡D­Y¬O¶KšìExcel VBA editor«á¡A§e
Post by 天道無常
Attribute
¹qž£»¡»yªk¿ù. «ç»ò¿ì?
§Ú€£ÀŽªºœÐ«ü±Ð
§Ú±N­ì¥ýªº "curTime = Now()" §ï¹L¡AŽ«Šš ActiveCell.Value¡D
¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
ªá¥Ò¯Î
2008-09-11 12:17:50 UTC
Permalink
œÐ«üŸÉ,ÁcÂಊpŠóŠwžËŠpŠóšÏ¥Î?
§A€]¥i¥H°ÑŠÒ§Ú€§«e°µªº¹AŸäŠ~šçŒÆ¡AŠ³šÏ¥Îªº€èªk€¶²Ð
http://chijanzen.net/wp/?p=45
ÁÙŠ³§A€]¥i¥H€Užü VBA µ{Š¡œX Ác²ÂàŽ«€ušã¡AŠÛ€v¥i¥HÂàŽ«
http://chijanzen.net/wp/?p=177
--
€ÑŠæ°·¡A§g€l¥HŠÛ±j€£®§
Ša¶Õ©[¡A§g€l¥H«pŒwžüª«
http://chijanzen.net
Post by ªá¥Ò¯Î
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
§ÚŠb§ÚªºExcel 2003€WžÕ¹L¡AšS°ÝÃD¡D¯à§_ŠC¥X§¹Ÿãªº¿ù»~°T®§¡H
§A­Y¬Oªœ±µ±N€U€å°Å¶KšìExcelªºVBA editor€€¡A·|Š³°ÝÃD¡AŠ]¬°Š³ªºµ{Š¡œX«Ü
ªø¡AŠÓ°Qœ×ª©Š³Œe«×­­šî¡A€Óªøªº·|€ÀŠššâŠæ¡D­Y¬O¶KšìExcel VBA editor«á¡A§e
Post by 天道無常
Attribute
¹qž£»¡»yªk¿ù. «ç»ò¿ì?
§Ú€£ÀŽªºœÐ«ü±Ð
§Ú±N­ì¥ýªº "curTime = Now()" §ï¹L¡AŽ«Šš ActiveCell.Value¡D
¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
hunter
2008-11-19 14:30:29 UTC
Permalink
"花甲翁" <***@47312.com> 在郵件 news:%***@TK2MSFTNGP06.phx.gbl
中撰寫...
請指導,繁轉簡如何安裝如何使用?
安裝及使用的位址如下連結請自行參閱

Office XP 簡繁轉換增益集

http://office.microsoft.com/search/redir.aspx?assetid=DC010512081028&url=http://www.microsoft.com/downloads/details.aspx?FamilyId=165CAF4B-E5EC-4CA8-AD60-859A696FCCB2&displaylang=zh-tw&hurl=93BADA56C6312C8C19F593C0D5D20BF9

Office 2003 簡繁轉換增益集

http://office.microsoft.com/search/redir.aspx?assetid=DC012119881028&url=http://www.microsoft.com/downloads/details.aspx?FamilyId=12538B0B-75BE-49BF-9557-BA11CC7A9B7A&displaylang=zh-tw&hurl=1923C5518535F4D1E17BC0714EB24870


office 2007簡繁轉換增益集在安裝選項中,預設應該會安裝,使用的話在『校閱』頁的『中文繁簡轉換』中。
Post by chijanzen
你也可以參考我之前做的農曆年函數,有使用的方法介紹
http://chijanzen.net/wp/?p=45
還有你也可以下載 VBA 程式碼 繁簡轉換工具,自己可以轉換
http://chijanzen.net/wp/?p=177
--
天行健,君子以自強不息
地勢坤,君子以厚德載物
http://chijanzen.net
Post by ªá¥Ò¯Î
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
這是一行嗎?
我做成一行了,但函數出錯誤值#name?
Post by 天道無常
我在我的Excel 2003上試過,沒問題.能否列出完整的錯誤訊息?
你若是直接將下文剪貼到Excel的VBA editor中,會有問題,因為有的程式碼很
長,而討論版有寬度限制,太長的會分成兩行.若是貼到Excel VBA editor後,呈
現紅字,那可能是一行被分成兩行,得自己將它合併成一行.
喔!"Attribute VB_Name = "Module1""這一行要刪去,不要貼到Excel中.那是我
天道無常
2008-09-06 19:20:01 UTC
Permalink
是的,但還有其他的:

TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38

NongliStr = "農曆" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"

上面這兩部份也要改成一行.

將我原先貼的程式貼到Excel VBA editor中,有問題的碼,Excel會以紅色顯現.
把紅色的及其下一行改成同一行即可.
Post by ªá¥Ò¯Î
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
這是一行嗎?
我做成一行了,但函數出錯誤值#name?
Post by 天道無常
我在我的Excel 2003上試過,沒問題.能否列出完整的錯誤訊息?
你若是直接將下文剪貼到Excel的VBA editor中,會有問題,因為有的程式碼很
長,而討論版有寬度限制,太長的會分成兩行.若是貼到Excel VBA editor後,呈
現紅字,那可能是一行被分成兩行,得自己將它合併成一行.
喔!"Attribute VB_Name = "Module1""這一行要刪去,不要貼到Excel中.那是我
將程式輸出為.bas檔時,Excel自己加了那一行.我貼文時,一時不察,忘了將那
一行刪去.抱歉!
Post by 天道無常
Attribute
電腦說語法錯. 怎麼辦?
我不懂的請指教
Post by 天道無常
我將原先的 "curTime = Now()" 改過,換成 ActiveCell.Value.
---------------------------
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'獲取當前系統時間
'curTime = Now()
curTime = ActiveCell.Value
'星期名
WeekName(0) = " * "
WeekName(1) = "星期日"
WeekName(2) = "星期一"
WeekName(3) = "星期二"
WeekName(4) = "星期三"
WeekName(5) = "星期四"
WeekName(6) = "星期五"
WeekName(7) = "星期六"
'天干名稱
TianGan(0) = "甲"
TianGan(1) = "乙"
TianGan(2) = "丙"
TianGan(3) = "丁"
TianGan(4) = "戊"
TianGan(5) = "己"
TianGan(6) = "庚"
TianGan(7) = "辛"
TianGan(8) = "壬"
TianGan(9) = "癸"
'地支名稱
DiZhi(0) = "子"
DiZhi(1) = "丑"
DiZhi(2) = "寅"
DiZhi(3) = "卯"
DiZhi(4) = "辰"
DiZhi(5) = "巳"
DiZhi(6) = "午"
DiZhi(7) = "未"
DiZhi(8) = "申"
DiZhi(9) = "酉"
DiZhi(10) = "戌"
DiZhi(11) = "亥"
'屬相名稱
ShuXiang(0) = "鼠"
ShuXiang(1) = "牛"
ShuXiang(2) = "虎"
ShuXiang(3) = "兔"
ShuXiang(4) = "龍"
ShuXiang(5) = "蛇"
ShuXiang(6) = "馬"
ShuXiang(7) = "羊"
ShuXiang(8) = "猴"
ShuXiang(9) = "雞"
ShuXiang(10) = "狗"
ShuXiang(11) = "豬"
'農曆日期名
DayName(0) = "*"
DayName(1) = "初一"
DayName(2) = "初二"
DayName(3) = "初三"
DayName(4) = "初四"
DayName(5) = "初五"
DayName(6) = "初六"
DayName(7) = "初七"
DayName(8) = "初八"
DayName(9) = "初九"
DayName(10) = "初十"
DayName(11) = "十一"
DayName(12) = "十二"
DayName(13) = "十三"
DayName(14) = "十四"
DayName(15) = "十五"
DayName(16) = "十六"
DayName(17) = "十七"
DayName(18) = "十八"
DayName(19) = "十九"
DayName(20) = "二十"
DayName(21) = "廿一"
DayName(22) = "廿二"
DayName(23) = "廿三"
DayName(24) = "廿四"
DayName(25) = "廿五"
DayName(26) = "廿六"
DayName(27) = "廿七"
DayName(28) = "廿八"
DayName(29) = "廿九"
DayName(30) = "三十"
'農曆月份名
MonName(0) = "*"
MonName(1) = "正"
MonName(2) = "二"
MonName(3) = "三"
MonName(4) = "四"
MonName(5) = "五"
MonName(6) = "六"
MonName(7) = "七"
MonName(8) = "八"
MonName(9) = "九"
MonName(10) = "十"
MonName(11) = "十一"
MonName(12) = "臘"
'公曆每月前面的天數
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'農曆數據
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'生成當前公曆年、月、日==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "年"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "月"
Else
GongliStr = GongliStr & curMonth & "月"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "日"
Else
GongliStr = GongliStr & curDay & "日"
End If
'生成當前公曆星期==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
'計算到初始時間1921年2月8日的天數:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'計算農曆天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'獲取NongliData(m)的第n個二進制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '生成農曆天干、地支、屬相==> NongliStr
NongliStr = "農曆" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'生成農曆月、日==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "閏" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "月"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
ªá¥Ò¯Î
2008-09-06 13:07:33 UTC
Permalink
§Ú·Qšì€F,€£ŠpœÐ§Aªœ±µ°µŠšŠÛ­qšçŒÆ
§âšÏ¥Î€FšçŒÆªºªþ¥ó¶K€WšÓ,§Úªœ±µÂàŠsšì§Ú¹qž£€€¥i€], ÁÂ!
§ÚŠb§ÚªºExcel 2003€WžÕ¹L¡AšS°ÝÃD¡D¯à§_ŠC¥X§¹Ÿãªº¿ù»~°T®§¡H
§A­Y¬Oªœ±µ±N€U€å°Å¶KšìExcelªºVBA editor€€¡A·|Š³°ÝÃD¡AŠ]¬°Š³ªºµ{Š¡œX«Ü
ªø¡AŠÓ°Qœ×ª©Š³Œe«×­­šî¡A€Óªøªº·|€ÀŠššâŠæ¡D­Y¬O¶KšìExcel VBA editor«á¡A§e
Post by 天道無常
Attribute
¹qž£»¡»yªk¿ù. «ç»ò¿ì?
§Ú€£ÀŽªºœÐ«ü±Ð
§Ú±N­ì¥ýªº "curTime = Now()" §ï¹L¡AŽ«Šš ActiveCell.Value¡D
¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '¥ÍŠš¹AŸä€Ñ€z¡BŠa€ä¡BÄݬÛ==> NongliStr
NongliStr = "¹AŸä" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "Š~"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'¥ÍŠš¹AŸä€ë¡B€é==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "¶|" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "ۑ"
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
天道無常
2008-09-06 19:25:24 UTC
Permalink
很抱歉!我從未用過自訂函數,不知如何用法.請見諒.
我想到了,不如請你直接做成自訂函數
把使用了函數的附件貼上來,我直接轉存到我電腦中可也, 謝!
ªá¥Ò¯Î
2008-09-07 11:05:06 UTC
Permalink
Šs€JŠìžm¡G
§Úªº°µªk¡þ¢ë¡þprogram files / microsoft office/office10 / xlstart
€U¬O¥Lªº¡G
¢°¡A±N¥H€Wµ{Š¡œXœÆ»sšìModule€€
¢±¡A±NÀÉ®×¥tŠs¬°*xlaÀÉ®×
¢²¡A±NŠ¹Àɮלƻsšì¡e®wžê®Æ§š¡fªºžô®|€€¡]c:program files/microsoft
Office/Office11/Library)
ª`·NŠsÀÉ®ÉÀÉ®×Ãþ«¬¡ÖŒW¯q¶°
ŠAŠb€ušã¡ÖŒW¯q¶°¡Ö€Ä¿ï€ÀªR€ušãœc


°ÑŠÒ
ŒÆ¶K¥XšÓ¡D
§ÚšÃšS§ï€°»ò¡A¥u¬O±N§A¶K¥XšÓªºµ{Š¡Ž«ŠšÁcÅéŠr¡AµM«á±N®É¶¡±q²{Šb®É¶¡(now
ªþ€W§Ú­ì¥ý¶Kªºµ{Š¡¡DšÏ¥Î€èªk¡G
€G¡B¥Ž¶}ExcelªºVBAœs¿èŸ¹¡]€ušã¡þ¥š¶°¡þVBAœs¿èŸ¹¡^
€T¡BŠbœs¿èŸ¹µøµ¡€€¡A¿ï¡uÀɮסþ?€JÀɮסK¡v¡A§ä¥X©ÒŠs€§ÀɧY¥i?€J¡D
(¶ñ€J€éŽÁ€§«á¡A³ÌŠnŠA¥H·Æ¹«ÂI¿ïžÓ®æ¡A¥HœT©w¥Š¬Oactivecell¡A®Ø€ñžû²Ê¡D)
­Y­n§ïŠ^­ì¥ý§A©Ò¶Kªºµ{Š¡€]¥i¡A€èªkŠp€U¡G
'Àòšú·í«ešt²Î®É¶¡
'curTime = Now()
curTime = ActiveCell.Value
ªí¥Ü¥Š€wžg€£¬OµùÄÀ¡AŠÓ¬Oµ{Š¡œX¡D
µM«á§Y¥i°õŠæžÓµ{Š¡¡D
¥Lªº¬OŠÛ­qšçŒÆœX,šçŒÆŠWºÙ¬O"zhuanhua "
»yªkŠp:=zhuanhua(a1,1)©Î=zhuanhua(a1,0)
zhuanhua = zhuanhua1
Else
zhuanhua = zhuanhua2µ¥
§Ú¬O§¹¥þ€£ÀŽvbaªº,Šý¹ï€ñŠÑ®v§ï«áªº»PšäŠ³«Ü€j®æŠ¡®t§O,¬O§_ŠÑ®vªº¬O¥š¶°?
(°e€Wªþ¥ó)
«Ü©êºp¡I§Ú±q¥Œ¥Î¹LŠÛ­qšçŒÆ¡A€£ªŸŠpŠó¥Îªk¡DœÐš£œÌ¡D
Post by ªá¥Ò¯Î
§Ú·Qšì€F,€£ŠpœÐ§Aªœ±µ°µŠšŠÛ­qšçŒÆ
§âšÏ¥Î€FšçŒÆªºªþ¥ó¶K€WšÓ,§Úªœ±µÂàŠsšì§Ú¹qž£€€¥i€], ÁÂ!
--------------------------------------------------------------------------------
Attribute VB_Name = "Module1"
Option Explicit
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
Private Sub Form_Load()
'et??
'curTime = Now()
curTime = ActiveCell.Value
'PW
WeekName(0) = " * "
WeekName(1) = "P"
WeekName(3) = "PG"
WeekName(4) = "PT"
WeekName(5) = "P|"
WeekName(6) = "P"
WeekName(7) = "P"
'?zW
TianGan(0) = ""
TianGan(1) = "A"
TianGan(2) = ""
TianGan(3) = "B"
TianGan(4) = ""
TianGan(5) = "v"
TianGan(6) = ""
TianGan(7) = ""
TianGan(8) = ""
TianGan(9) = ""
'aW
DiZhi(0) = "l"
DiZhi(1) = ""
DiZhi(2) = "G"
DiZhi(3) = "f"
DiZhi(4) = ""
DiZhi(5) = "x"
DiZhi(6) = ""
DiZhi(7) = ""
DiZhi(8) = ""
DiZhi(9) = ""
DiZhi(10) = ""
DiZhi(11) = ""
'??W
ShuXiang(0) = ""
ShuXiang(1) = ""
ShuXiang(2) = ""
ShuXiang(3) = ""
ShuXiang(4) = "s"
ShuXiang(5) = "D"
ShuXiang(6) = ""
ShuXiang(7) = ""
ShuXiang(8) = "U"
ShuXiang(9) = ""
ShuXiang(10) = ""
ShuXiang(11) = ""
'AW
DayName(0) = "*"
DayName(2) = "G"
DayName(3) = "T"
DayName(4) = "|"
DayName(5) = "?"
DayName(6) = "?"
DayName(7) = "C"
DayName(8) = "K"
DayName(9) = "E"
DayName(10) = "Q"
DayName(12) = "QG"
DayName(13) = "QT"
DayName(14) = "Q|"
DayName(15) = "Q"
DayName(16) = "Q"
DayName(17) = "QC"
DayName(18) = "QK"
DayName(19) = "QE"
DayName(20) = "GQ"
DayName(22) = "?G"
DayName(23) = "?T"
DayName(24) = "?|"
DayName(25) = "?"
DayName(26) = "?"
DayName(27) = "?C"
DayName(28) = "?K"
DayName(29) = "?E"
DayName(30) = "TQ"
'AW
MonName(0) = "*"
MonName(1) = ""
MonName(2) = "G"
MonName(3) = "T"
MonName(4) = "|"
MonName(5) = ""
MonName(6) = ""
MonName(7) = "C"
MonName(8) = "K"
MonName(9) = "E"
MonName(10) = "Q"
MonName(12) = "t"
'Ce?
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'A?
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'?e~BB==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & ""
Else
GongliStr = GongliStr & curMonth & ""
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & ""
Else
GongliStr = GongliStr & curDay & ""
End If
'?eP==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'pA?zBaBB
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'NongliData(m)n?Gi?
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '?A?zBaB?==> NongliStr
NongliStr = "A" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "~"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'?AB==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "|" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & ""
NongliDayStr = NongliDayStr & DayName(curDay)
MsgBox NongliStr & NongliDayStr
End Sub
天道無常
2008-09-12 01:40:34 UTC
Permalink
試了半天,總算試成功.

===================

Function test(curTime As Date) As String

Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate


'星期名
WeekName(0) = " * "
WeekName(1) = "星期日"
WeekName(2) = "星期一"
WeekName(3) = "星期二"
WeekName(4) = "星期三"
WeekName(5) = "星期四"
WeekName(6) = "星期五"
WeekName(7) = "星期六"
'天干名稱
TianGan(0) = "甲"
TianGan(1) = "乙"
TianGan(2) = "丙"
TianGan(3) = "丁"
TianGan(4) = "戊"
TianGan(5) = "己"
TianGan(6) = "庚"
TianGan(7) = "辛"
TianGan(8) = "壬"
TianGan(9) = "癸"
'地支名稱
DiZhi(0) = "子"
DiZhi(1) = "丑"
DiZhi(2) = "寅"
DiZhi(3) = "卯"
DiZhi(4) = "辰"
DiZhi(5) = "巳"
DiZhi(6) = "午"
DiZhi(7) = "未"
DiZhi(8) = "申"
DiZhi(9) = "酉"
DiZhi(10) = "戌"
DiZhi(11) = "亥"
'屬相名稱
ShuXiang(0) = "鼠"
ShuXiang(1) = "牛"
ShuXiang(2) = "虎"
ShuXiang(3) = "兔"
ShuXiang(4) = "龍"
ShuXiang(5) = "蛇"
ShuXiang(6) = "馬"
ShuXiang(7) = "羊"
ShuXiang(8) = "猴"
ShuXiang(9) = "雞"
ShuXiang(10) = "狗"
ShuXiang(11) = "豬"
'農曆日期名
DayName(0) = "*"
DayName(1) = "初一"
DayName(2) = "初二"
DayName(3) = "初三"
DayName(4) = "初四"
DayName(5) = "初五"
DayName(6) = "初六"
DayName(7) = "初七"
DayName(8) = "初八"
DayName(9) = "初九"
DayName(10) = "初十"
DayName(11) = "十一"
DayName(12) = "十二"
DayName(13) = "十三"
DayName(14) = "十四"
DayName(15) = "十五"
DayName(16) = "十六"
DayName(17) = "十七"
DayName(18) = "十八"
DayName(19) = "十九"
DayName(20) = "二十"
DayName(21) = "廿一"
DayName(22) = "廿二"
DayName(23) = "廿三"
DayName(24) = "廿四"
DayName(25) = "廿五"
DayName(26) = "廿六"
DayName(27) = "廿七"
DayName(28) = "廿八"
DayName(29) = "廿九"
DayName(30) = "三十"
'農曆月份名
MonName(0) = "*"
MonName(1) = "正"
MonName(2) = "二"
MonName(3) = "三"
MonName(4) = "四"
MonName(5) = "五"
MonName(6) = "六"
MonName(7) = "七"
MonName(8) = "八"
MonName(9) = "九"
MonName(10) = "十"
MonName(11) = "十一"
MonName(12) = "臘"
'公曆每月前面的天數
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'農曆數據
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'生成當前公曆年、月、日==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "年"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "月"
Else
GongliStr = GongliStr & curMonth & "月"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "日"
Else
GongliStr = GongliStr & curDay & "日"
End If
'生成當前公曆星期==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
'計算到初始時間1921年2月8日的天數:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'計算農曆天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'獲取NongliData(m)的第n個二進制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '生成農曆天干、地支、屬相==> NongliStr
NongliStr = "農曆" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'生成農曆月、日==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "閏" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "月"
NongliDayStr = NongliDayStr & DayName(curDay)
'MsgBox NongliStr & NongliDayStr

test = NongliStr & NongliDayStr

End Function
ªá¥Ò¯Î
2008-09-12 11:11:03 UTC
Permalink
1,œÐ±ÐšÏ¥Î€èªk
2,¬O§_ŠÛ­qšçŒÆœX?šçŒÆŠWºÙ¬O«çŒËªº?
3,§Ú¶Kšìvbaœs¿è®ÉŠ³«ÜŠh"????"¬OŠóŠ]?«ç»ò¿ì?
žÕ€F¥b€Ñ¡AÁ`ºâžÕŠš¥\¡D
¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×¡×
Function test(curTime As Date) As String
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11),
ShuXiang(11), DayName(30), MonName(12)
Dim curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
'¬PŽÁŠW
WeekName(0) = " * "
WeekName(1) = "¬PŽÁ€é"
WeekName(3) = "¬PŽÁ€G"
WeekName(4) = "¬PŽÁ€T"
WeekName(5) = "¬PŽÁ¥|"
WeekName(6) = "¬PŽÁ€­"
WeekName(7) = "¬PŽÁ€»"
'€Ñ€zŠWºÙ
TianGan(0) = "¥Ò"
TianGan(1) = "€A"
TianGan(2) = "€þ"
TianGan(3) = "€B"
TianGan(4) = "¥³"
TianGan(5) = "€v"
TianGan(6) = "©°"
TianGan(7) = "š¯"
TianGan(8) = "€Ð"
TianGan(9) = "„"
'Ša€äŠWºÙ
DiZhi(0) = "€l"
DiZhi(1) = "€¡"
DiZhi(2) = "±G"
DiZhi(3) = "¥f"
DiZhi(4) = "š°"
DiZhi(5) = "€x"
DiZhi(6) = "€È"
DiZhi(7) = "¥Œ"
DiZhi(8) = "¥Ó"
DiZhi(9) = "š»"
DiZhi(10) = "ŠŠ"
DiZhi(11) = "¥è"
'ÄݬۊWºÙ
ShuXiang(0) = "¹«"
ShuXiang(1) = "€û"
ShuXiang(2) = "ªê"
ShuXiang(3) = "šß"
ShuXiang(4) = "Às"
ShuXiang(5) = "³D"
ShuXiang(6) = "°š"
ShuXiang(7) = "ŠÏ"
ShuXiang(8) = "µU"
ShuXiang(9) = "Âû"
ShuXiang(10) = "ª¯"
ShuXiang(11) = "œÞ"
'¹AŸä€éŽÁŠW
DayName(0) = "*"
DayName(2) = "ªì€G"
DayName(3) = "ªì€T"
DayName(4) = "ªì¥|"
DayName(5) = "ªì€­"
DayName(6) = "ªì€»"
DayName(7) = "ªì€C"
DayName(8) = "ªì€K"
DayName(9) = "ªì€E"
DayName(10) = "ªì€Q"
DayName(12) = "€Q€G"
DayName(13) = "€Q€T"
DayName(14) = "€Q¥|"
DayName(15) = "€Q€­"
DayName(16) = "€Q€»"
DayName(17) = "€Q€C"
DayName(18) = "€Q€K"
DayName(19) = "€Q€E"
DayName(20) = "€G€Q"
DayName(22) = "€Ü€G"
DayName(23) = "€Ü€T"
DayName(24) = "€Ü¥|"
DayName(25) = "€Ü€­"
DayName(26) = "€Ü€»"
DayName(27) = "€Ü€C"
DayName(28) = "€Ü€K"
DayName(29) = "€Ü€E"
DayName(30) = "€T€Q"
'¹AŸä€ë¥÷ŠW
MonName(0) = "*"
MonName(1) = "¥¿"
MonName(2) = "€G"
MonName(3) = "€T"
MonName(4) = "¥|"
MonName(5) = "€­"
MonName(6) = "€»"
MonName(7) = "€C"
MonName(8) = "€K"
MonName(9) = "€E"
MonName(10) = "€Q"
MonName(12) = "ß"
'€œŸäšC€ë«e­±ªº€ÑŒÆ
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'¹AŸäŒÆŸÚ
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
'¥ÍŠš·í«e€œŸäŠ~¡B€ë¡B€é==> GongliStr
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
GongliStr = curYear & "Š~"
If (curMonth < 10) Then
GongliStr = GongliStr & "0" & curMonth & "ۑ"
Else
GongliStr = GongliStr & curMonth & "ۑ"
End If
If (curDay < 10) Then
GongliStr = GongliStr & "0" & curDay & "ێ"
Else
GongliStr = GongliStr & curDay & "ێ"
End If
'¥ÍŠš·í«e€œŸä¬PŽÁ==> WeekdayStr
curWeekday = Weekday(curTime)
WeekdayStr = WeekName(curWeekday)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay +
MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'­pºâ¹AŸä€Ñ€z¡BŠa€ä¡B€ë¡B€é
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'ÀòšúNongliData(m)ªº²Än­Ó€G¶išîŠìªº­È
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If '¥ÍŠš¹AŸä€Ñ€z¡BŠa€ä¡BÄݬÛ==> NongliStr
NongliStr = "¹AŸä" & TianGan(((curYear - 4) Mod 60) Mod 10) &
DiZhi(((curYear - 4) Mod 60) Mod 12) & "Š~"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'¥ÍŠš¹AŸä€ë¡B€é==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "¶|" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "ۑ"
NongliDayStr = NongliDayStr & DayName(curDay)
'MsgBox NongliStr & NongliDayStr
test = NongliStr & NongliDayStr
End Function
天道無常
2008-09-13 02:11:18 UTC
Permalink
一、將檔案複製到notepad中.
二、前述太長那三行,各自與其下一行合併為一行.
三、檔案最前方加入下面這一行

Attribute VB_Name = "Module1"

四、儲存檔案,命名為test.bas
五、進入Excel的VBA Editor,選import file,滙入test.bas

使用法:

若A1欄是日期的話,在任一欄中輸入方程式:

=test(A1)
1,請教使用方法
2,是否自訂函數碼?函數名稱是怎樣的?
3,我貼到vba編輯時有很多"????"是何因?怎麼辦?
ªá¥Ò¯Î
2008-09-14 00:20:37 UTC
Permalink
œÐ§â§AšÏ¥Î€FšçŒÆªºªþ¥ó¶K€WšÓŠn¶Ü
Post by 天道無常
Attribute VB_Name = "Module1"
¥|¡BÀxŠsÀɮסA©RŠW¬°test.bas
€­¡B¶i€JExcelªºVBA Editor¡A¿ïimport file¡A?€Jtest.bas
šÏ¥Îªk¡G
=test(A1)
Post by ªá¥Ò¯Î
1,œÐ±ÐšÏ¥Î€èªk
2,¬O§_ŠÛ­qšçŒÆœX?šçŒÆŠWºÙ¬O«çŒËªº?
3,§Ú¶Kšìvbaœs¿è®ÉŠ³«ÜŠh"????"¬OŠóŠ]?«ç»ò¿ì?
ªá¥Ò¯Î
2008-09-14 03:14:29 UTC
Permalink
¬°Šó§ÚÀxŠs®ÉµLªk¥hšìofficeŠìžm,Á`¬O¶i€J2007?
(2003)
Post by ªá¥Ò¯Î
œÐ§â§AšÏ¥Î€FšçŒÆªºªþ¥ó¶K€WšÓŠn¶Ü
Post by 天道無常
Attribute VB_Name = "Module1"
¥|¡BÀxŠsÀɮסA©RŠW¬°test.bas
€­¡B¶i€JExcelªºVBA Editor¡A¿ïimport file¡A?€Jtest.bas
šÏ¥Îªk¡G
=test(A1)
Post by ªá¥Ò¯Î
1,œÐ±ÐšÏ¥Î€èªk
2,¬O§_ŠÛ­qšçŒÆœX?šçŒÆŠWºÙ¬O«çŒËªº?
3,§Ú¶Kšìvbaœs¿è®ÉŠ³«ÜŠh"????"¬OŠóŠ]?«ç»ò¿ì?
ªá¥Ò¯Î
2008-09-14 03:40:03 UTC
Permalink
ÁÂ! Šn¹³žÑšM€F
Post by ªá¥Ò¯Î
œÐ§â§AšÏ¥Î€FšçŒÆªºªþ¥ó¶K€WšÓŠn¶Ü
Post by 天道無常
Attribute VB_Name = "Module1"
¥|¡BÀxŠsÀɮסA©RŠW¬°test.bas
€­¡B¶i€JExcelªºVBA Editor¡A¿ïimport file¡A?€Jtest.bas
šÏ¥Îªk¡G
=test(A1)
Post by ªá¥Ò¯Î
1,œÐ±ÐšÏ¥Î€èªk
2,¬O§_ŠÛ­qšçŒÆœX?šçŒÆŠWºÙ¬O«çŒËªº?
3,§Ú¶Kšìvbaœs¿è®ÉŠ³«ÜŠh"????"¬OŠóŠ]?«ç»ò¿ì?
Loading...