Board logo

標題: 請教 Excel VBA 儲存格月曆設定問題 [打印本頁]

作者: jsc0518    時間: 2017-4-25 12:50     標題: 請教 Excel VBA 儲存格月曆設定問題

大家好,我在網路上有下載到網友已寫完成的點選指定儲存格後,月曆會show出欄點選
但我把程式碼copy到新的Excel上卻發生錯誤
是否哪一個語法我需要修改,請各位先進指導
感謝大家!



Private Sub Calendar1_Click()
Selection.Value = Calendar1.Value
Calendar1.Visible = False
Calendar1.Value = Date
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'若要增加欲插入日期的欄位, 則修改下面這行的 3, 或 6 數字
If Target.Column <> 3 And Target.Column <> 6 Then Calendar1.Visible = fales: Exit Sub
'Calendar1.Top = (Target.Row - 1) * 16.5

Calendar1.Top = ActiveCell.Top   '這兩行決定月曆控制項的位置
Calendar1.Left = ActiveCell.Left + 80

Calendar1.Visible = True
End Sub








錯誤畫面如下

[attach]27085[/attach]

原始檔案
[attach]27086[/attach]
作者: starry1314    時間: 2017-4-25 13:48

用這個吧
把裡面的表單和物件類別模組放到妳想要用的檔案裡面
再用以下指令 取控制點選哪裡跳出日曆控制項
輸出位置=滑鼠點選位置
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells(1).Address = "$B$6" Then 日曆.Show '點選B6則跳出日曆

End Sub

[attach]27087[/attach]
作者: jsc0518    時間: 2017-4-25 15:40

回復 2# starry1314

Hi starry1314,
感謝您的回應
因本身為初學者,還不是很懂VBA的相關用法,
跟您請教一下--> "把裡面的表單和物件類別模組放到妳想要用的檔案裡面"
這個動作要怎麼做阿?

感恩!


    [attach]27088[/attach]
作者: jsc0518    時間: 2017-4-25 16:05

回復 2# starry1314


Hi,我已經知道如何匯入您所提供的檔案模組了
請教一下,若我想在B2~B1000,整個都是可以選擇月曆的選項,我該如何修該您的語法呢?
Thanks!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells(1).Address = "$B$6" Then 日曆.Show '點選B6則跳出日曆

End Sub

作者: hungrn    時間: 2017-4-25 20:25

If Not Intersect(Target, Range("B2:B1000")) Is Nothing Then
       日曆.Show
    End If
作者: jsc0518    時間: 2017-4-26 08:33

回復 5# hungrn

Test ok , 感謝您的回覆與指導!




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)