Modifying Calendar Code

ditto

New Member
Joined
Mar 21, 2009
Messages
20
I am using the following pieces of code for date input in cells. Can anyone please help me to modify the calendar to always put the dates in the format dd/mm/yyyy whatever be the other settings (like system date format and cell formatting).
On Sheet1
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, [A1:D4,F1:H4]) Is Nothing And Target.Address = Target(1).MergeArea.Address Then
        ShowCalendarInputControl Target
    Else
        HideCalendarInputControl
    End If
End Sub
Public Sub CalendarInputControl_DblClick()
    HideCalendarInputControl
End Sub
In Module1
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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top