In my workbook there are some cells for date entry. I have put excel popup calendars in these cells. But I want the calendar to put the date in the English(UK) format ie. dd/mm/yyyy. But this workbook goes to many places and I want the calendar to put the date in the said format even if the system date format is defined otherwise. Is there a way to change the system date fomat on opening a workbook? Or should I modify the code for the calendar given below?
Code:
Option Explicit
Private Const CalendarInputControlName = "CalendarInputControl"
Private Const CalendarInputFrame1Name = "CalendarInputFrame1"
Private Const CalendarInputFrame2Name = "CalendarInputFrame2"
Public Sub HideCalendarInputControl()
On Error Resume Next
ActiveSheet.OLEObjects(CalendarInputControlName).Delete
ActiveSheet.Shapes(CalendarInputFrame1Name).Delete
ActiveSheet.Shapes(CalendarInputFrame2Name).Delete
End Sub
Public Sub ShowCalendarInputControl( _
ByVal Cell As Range _
)
Dim Calendar As Object
Dim CalendarFrame As Shape
Dim CellFrame As Shape
Dim HorizontalDelta As Double
Dim VerticalDelta As Double
HideCalendarInputControl
If Cell.Left + Cell.Width + 5 + 182.5 > ActiveWindow.VisibleRange.Columns(ActiveWindow.VisibleRange.Columns.Count).Left Then
HorizontalDelta = -Cell.Width - 10 - 182.5
End If
If Cell.Top + Cell.Height + 5 + 123 > ActiveWindow.VisibleRange.Rows(ActiveWindow.VisibleRange.Rows.Count).Top Then
VerticalDelta = -Cell.Height - 10 - 123
End If
Set CellFrame = ActiveSheet.Shapes.AddShape(msoShapeRectangle, Cell.Left, Cell.Top, Cell.Width + 1, Cell.Height + 1)
CellFrame.Name = CalendarInputFrame1Name
With CellFrame.OLEFormat.Object.ShapeRange
.Fill.Visible = msoFalse
.Line.ForeColor.SchemeColor = 12
.Line.Weight = 2.5
End With
Set CalendarFrame = ActiveSheet.Shapes.AddShape(msoShapeRectangle, Cell.Left + Cell.Width + 5 + HorizontalDelta, Cell.Top + Cell.Height + 5 + VerticalDelta, 182.5, 123)
CalendarFrame.Name = CalendarInputFrame2Name
With CalendarFrame.OLEFormat.Object.ShapeRange
.Fill.Visible = msoFalse
.Line.ForeColor.SchemeColor = 12
.Line.Weight = 2.5
End With
On Error Resume Next
Set Calendar = ActiveSheet.OLEObjects.Add(ClassType:="MSCAL.Calendar.7", Left:=Cell.Left + Cell.Width + 7 + HorizontalDelta, Top:=Cell.Top + Cell.Height + 7 + VerticalDelta, Width:=180, Height:=120)
If Err.Number <> 0 Then
MsgBox "The Microsoft Calendar Control is not installed on this computer."
HideCalendarInputControl
Exit Sub
End If
Calendar.Name = CalendarInputControlName
Calendar.LinkedCell = Cell.Address
Calendar.Visible = False
Calendar.Visible = True
End Sub