返回列表 上一主題 發帖

利用VBA 表單製作萬年曆?

本帖最後由 GBKEE 於 2013-3-25 20:34 編輯

回復 4# mark15jill
試試看

DSC00220[1].JPG.rar (13.38 KB)
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 6# Jared
但程式就判斷找不到DAY_i.Caption 這個成員....
沒有檔案看不到 DAY_i 是如何設定的,是這樣嗎?
  1. Controls("DAY_" & I).Caption
複製代碼
回復 4# mark15jill

圖片上的程式碼,需要有好眼力才看的到,何不代碼貼上來
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 9# Jared
  1. 這個月的第一天    DateSerial(ComboBox1, ComboBox2, 1)
  2. 這個月的最後一天 DateSerial(ComboBox1, ComboBox2.Value + 1, 0)
複製代碼
修改 5# 檔案 表單程式碼 如下
  1. Option Explicit
  2. Dim Class_OB(1 To 7, 1 To 6) As New Class1
  3. Private Sub UserForm_Initialize()
  4.     Dim I As Integer
  5.      日期項
  6.     For I = 1980 To 2099
  7.         ComboBox1.AddItem I
  8.     Next
  9.     ComboBox1.Value = Year(Date)
  10.     For I = 1 To 12
  11.         ComboBox2.AddItem I
  12.     Next
  13.     ComboBox2.Value = Month(Date)
  14. End Sub
  15. Private Sub ComboBox1_Change()
  16.     月曆
  17. End Sub
  18. Private Sub ComboBox2_Change()
  19.     月曆
  20. End Sub
  21. Private Sub 月曆()
  22.    月曆清除
  23.     If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then 萬年曆
  24. End Sub
  25. Private Sub 萬年曆()
  26.     Dim R As Integer, I As Date, WD As Integer
  27.      R = 1
  28.      For I = DateSerial(ComboBox1, ComboBox2, 1) To DateSerial(ComboBox1, ComboBox2.Value + 1, 0)
  29.         WD = Weekday(I)
  30.         With Controls(R & "_" & WD)
  31.             .Enabled = True
  32.             .Caption = Day(I)
  33.             .ControlTipText = I
  34.         End With
  35.         If WD = 7 Then R = R + 1
  36.      Next
  37. End Sub
  38. Private Sub 日期項()
  39.     Dim OBtop As Integer, OBLeft As Integer, R As Integer
  40.     Dim OB_1 As Integer, OB_2 As Integer
  41.     R = Label1.Top + 30
  42.       For OB_2 = 1 To UBound(Class_OB, 2)
  43.         For OB_1 = 1 To UBound(Class_OB, 1)
  44.             With Controls.Add("Forms.OptionButton.1", OB_2 & "_" & OB_1)
  45.                 .Visible = True
  46.                 .Top = R '
  47.                 .Left = Controls("Label" & OB_1).Left
  48.                 'Controls("Label" & OB_1)->已建立星期之 Label控制項
  49.                 '名稱依序為Label1,Label2,Label3,Label4,Label5,Label6,Label7.
  50.                 .Height = 15
  51.                 .Width = 30
  52.                 .ControlTipText = ""
  53.             End With
  54.             Set Class_OB(OB_1, OB_2).OB = Controls(OB_2 & "_" & OB_1)
  55.         Next
  56.         R = R + 30
  57.      Next
  58. End Sub
  59. Private Sub 月曆清除()
  60.     Dim E As Control
  61.     For Each E In Me.Controls
  62.         If E.Name Like "*_*" Then
  63.             E.Enabled = False
  64.             E.Caption = ""
  65.             E.ControlTipText = ""
  66.         End If
  67.     Next
  68. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 14# Jared
物件類別模組 Class1
  1. Option Explicit
  2. Public WithEvents OB As MSForms.OptionButton
  3. Private Sub OB_Click()
  4.     'MsgBox OB.Caption
  5.     '年月日
  6.     Sheet1.[a1] = OB.ControlTipText
  7.     '日期
  8.     'Sheet1.[a1] = OB.Caption
  9. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 17# mark15jill
   
<天數對  星期錯亂>
星期錯亂: 你是用何函數
傳上程式碼看看
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2013-3-27 13:33 編輯

回復 19# mark15jill
你好像繞了一圈.
回復 21# mark15jill
製作陽曆萬年曆與潤2月是沒有關係的
  1. Sub Ex()
  2.     Dim D As String
  3.     D = "2013/2/21"
  4.     MsgBox D & " 後一天 " & DateSerial(Year(D), Month(D) + 1, 0)
  5.     '每月的後一天
  6.     MsgBox Format(D, "aaa")
  7. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 願要大、志要堅、氣要柔、心要細。
返回列表 上一主題