Chào các bác, lại là em Gà đây
trước hết em muốn chia sẻ Calendar picker mà em sưu tầm của bác Trevor Eyre có hiệu ứng rất đẹp.
thứ 2 là em muốn làm phiền các bác chỉ giáo giúp em cách kết hợp nó với code lấy vị trí hiển thị userform của bác Mr.hieudoanxd với ạ
1.............Code bác Mr.Hieu Doan
#If Win64 And VBA7 Then
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hDc As LongPtr) As Long
Dim hDc As LongPtr
#Else
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDc As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDc As Long) As Long
Dim hDc As Long
#End If
Type POINTAPI
X As Long
Y As Long
End Type
Sub SetUpForm(ctrlForm As Object, Rng As Range)
With ctrlForm
.startupposition = 0
'.Height = 18
.Left = TopLeftPoint(Rng).X + 90
.Top = TopLeftPoint(Rng).Y + 90 '+ Rng.Height
End With
End Sub
Private Function TopLeftPoint(ByVal Alan As Range) As POINTAPI
Const LOGPIXELSX As Long = 88
Const LOGPIXELSY As Long = 90
Const PointsPerInch = 72
Dim PixelsPerPointX As Double
Dim PixelsPerPointY As Double
Dim PointsPerPixelX As Double
Dim PointsPerPixelY As Double
hDc = GetDC(0)
PixelsPerPointX = GetDeviceCaps(hDc, LOGPIXELSX) / PointsPerInch
PointsPerPixelX = PointsPerInch / GetDeviceCaps(hDc, LOGPIXELSX)
PixelsPerPointY = GetDeviceCaps(hDc, LOGPIXELSY) / PointsPerInch
PointsPerPixelY = PointsPerInch / GetDeviceCaps(hDc, LOGPIXELSY)
With TopLeftPoint
.X = ActiveWindow.PointsToScreenPixelsX(Alan.Left * (PixelsPerPointX * (ActiveWindow.Zoom / 100))) * PointsPerPixelX
.Y = ActiveWindow.PointsToScreenPixelsY(Alan.Top * (PixelsPerPointY * (ActiveWindow.Zoom / 100))) * PointsPerPixelY
End With
ReleaseDC 0, hDc
End Function
2....... code gọi Calendar picker
Sub AdvancedCalendar2()
Dim dateVariable
SetUpForm CalendarForm, Selection 'Đây là phần em thêm nhưng nó không điều chỉnh được vị trí hiển thị đúng
dateVariable = CalendarForm.GetDate( _
SelectedDate:=Date, _
DateFontSize:=11, _
TodayButton:=True, _
BackgroundColor:=RGB(242, 248, 238), _
HeaderColor:=RGB(84, 130, 53), _
HeaderFontColor:=RGB(255, 255, 255), _
SubHeaderColor:=RGB(226, 239, 218), _
SubHeaderFontColor:=RGB(55, 86, 35), _
DateColor:=RGB(242, 248, 238), _
DateFontColor:=RGB(55, 86, 35), _
SaturdayFontColor:=RGB(55, 86, 35), _
SundayFontColor:=RGB(55, 86, 35), _
TrailingMonthFontColor:=RGB(106, 163, 67), _
DateHoverColor:=RGB(198, 224, 180), _
DateSelectedColor:=RGB(169, 208, 142), _
TodayFontColor:=RGB(255, 0, 0), _
DateSpecialEffect:=fmSpecialEffectRaised)
If dateVariable <> 0 Then ActiveCell = dateVariable
End Sub