本帖最后由 lss001 于 2020-1-23 20:34 编辑
Sub auto_Open() 'Excel底部状态栏显示公历农历(1900-2100) Dim a, b, c, e, f, g, h, i, j, k, m, n, p, q, r, s, t, u, v, x, y, s1,s2, s3, s4, e1, e2, e3, e4, r1, r2, _ j1, j2, jj, gq, nq, gj, nj, jr, js, jt, jz, jx, zn, zy, zr, zs, rq, t1,t2, t3, t4, f1, f2, f3, f4, am, rm, cm Set js = CreateObject("scriptcontrol"): js.Language ="jscript": gq = Date '***** s = "var nf=new Array(" & _ "0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,"& _ "0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,"& _ "0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,"& _ "0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,"& _ "0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,"& _ "0x06ca0,0x0b550,0x15355,0x04da0,0x0a5b0,0x14573,0x052b0,0x0a9a8,0x0e950,0x06aa0,"& _ "0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,"& _ "0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b6a0,0x195a6,"& _ "0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,"& _ "0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,"& _ "0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,"& _ "0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,"& _ "0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,"& _ "0x05aa0,0x076a3,0x096d0,0x04afb,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,"& _ "0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0,"& _ "0x14b63,0x09370,0x049f8,0x04970,0x064b0,0x168a6,0x0ea50,0x06b20,0x1a6c4,0x0aae0,"& _ "0x0a2e0,0x0d2e3,0x0c960,0x0d557,0x0d4a0,0x0da50,0x05d55,0x056a0,0x0a6d0,0x055d4,"& _ "0x052d0,0x0a9b8,0x0a950,0x0b4a0,0x0b6a6,0x0ad50,0x055a0,0x0aba4,0x0a5b0,0x052b0,"& _ "0x0b273,0x06930,0x07337,0x06aa0,0x0ad50,0x14b55,0x04b60,0x0a570,0x054e4,0x0d160,"& _ "0x0e968,0x0d520,0x0daa0,0x16aa6,0x056d0,0x04ae0,0x0a9d4,0x0a2d0,0x0d150,0x0f252,0x0d520);"& _ "var j,r,de=new nDate(new Date(""" & gq &"""));" '农历数据 s = s & "function m(y){return(nf[y-1900]&0xf)};" '返回农历y年闰月1-12/没闰返回 0 s = s & "functionmd(y,m){return((nf[y-1900]&(0x10000>>m))?30:29)};r=md(de.year,de.month);"'返回农历y年m月的天数 s = s & "functionxd(y){if(m(y))return((nf[y-1900]&0x10000)?30:29);else return(0)};" '返回农历y年闰月的天数 s = s & "function yd(y){var i,s=348;for(i=0x8000;i>0x8;i>>=1)s+=(nf[y-1900]&i)?1:0;return(s+xd(y))};"'返回农历y年的总天数 s = s & "function nDate(n){var i,p=0,t=0," & _ "f=(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate())-Date.UTC(1900,0,31))/864e5;"& _ "for(i=1900;i<2100&&f>0;i++){t=yd(i);f-=t;}"& _ "if(f<0){f+=t;i--;}this.year=i;p=m(i);this.sp=false;" &_ "for(i=1;i<13&&f>0;i++){if(p>0&&i==(p+1)&&this.sp==false)"& _ "{--i;this.sp=true;t=xd(this.year);}else{t=md(this.year,i);}"& _ "if(this.sp==true&&i==(p+1))this.sp=false;f-=t;}"& _ "if(f==0&&p>0&&i==p+1)if(this.sp){this.sp=false;}else{this.sp=true;--i;}"& _ "if(f<0){f+=t;--i;}this.month=i;this.j=this.sp;this.day=f+1;};"& _ "y=de.year;m=de.month;d=de.day;j=de.j;y+'-'+m+'-'+d+'>'+r+'<'+j"'返回农历日期/闰月数据 h = js.Eval(s): k = IIf(Mid(h, InStrRev(h, "<") + 1, 5) ="true", "闰", "") nq = Format(Left(h, InStr(1, h, ">") - 1), "yyyy/mm/dd") jr = Split("小寒,大寒,立春,雨水,惊蛰,春分,清明,谷雨,立夏,小满,芒种,夏至," & _ "小暑,大暑,立秋,处暑,白露,秋分,寒露,霜降,立冬,小雪,大雪,冬至", ",") jt = Split("0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,"& _ "263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758",",") js.addcode "function jq(r,s){var d=new Date((31556925974.7*(r-1900)+s*60000)+Date.UTC(1900,0,6,2,5));return(d.getUTCDate())}" ReDim jz(0 To 23) For i = 0 To 23 '返回某年的第n个节气为几日/从0小寒算起 r = js.Run("jq", Year(gq), jt(i)) If i < 18 Then jz(i) = "0" & (i + 2) \ 2 Else jz(i) =(i + 2) \ 2 If r < 10 Then jz(i) = Year(gq) & "/" & jz(i) &"/" & "0" & r Else jz(i) = Year(gq) &"/" & jz(i) & "/" & r Next For i = 0 To Month(gq) * 2 - 1 '//节气 If gq = CDate(jz(i)) Then a = jr(i): Exit For Next gj = Split("0101元旦,0308妇女节,0312植树节,0501劳动节,0504青年节,0512护士节,0601儿童节,0701建党节,0801建军节,0910教师节,1001国庆节", ",") For i = 0 To UBound(gj) '//公历节日 If Format(gq, "mmdd") = Left(gj(i), 4) Then b = Mid(gj(i), 5,3): Exit For Next
补充内容 (2020-3-9 19:43):
'节气显示修改如下:
For I = Month(gq) * 2 - 1 To 0 Step -1 '//节气
If gq >= CDate(jz(I)) Then
a = jr(I): Exit For
End If
Next
If a = "" Then a = jr(23) |