Consulting

Results 1 to 4 of 4

Thread: Solved: Calendar control woes

  1. #1
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location

    Solved: Calendar control woes

    Hi All,

    Having a bit of a problem while using the cal control programmatically.

    Can someone do me a favor and run this code?[vba]Sub scc()
    ActiveSheet.OLEObjects.Add ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150
    End Sub[/vba]Assuming design mode is off when it is run, it does add a calendar control to the sheet but it is not interactive. If you turn on design mode then turn it back off, it becomes interactive (and you can see it change color slightly when interactive).

    Any ideas what I can do? I left the version off the cal control on purpose as it will probably be run on different machines.

    Truth be told, it is for a selection change event, see:[vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address(0, 0) <> "D5" Then Exit Sub
    Application.EnableEvents = False
    With ActiveSheet.OLEObjects.Add(ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150)
    .Name = "CalControl1"
    End With
    Application.EnableEvents = True
    End Sub
    Private Sub CalControl1_Click()
    Range("D5").Value = CalControl1.Value
    Shapes("CalControl1").Delete
    End Sub[/vba]
    Any help/thoughts/confirmations would be appreciated
    Matt

  2. #2
    VBAX Tutor Philcjr's Avatar
    Joined
    Jul 2005
    Location
    Bedminster, NJ
    Posts
    208
    Location
    Matt,

    I am no guru, but I tried your code and I could not select the calendar as well.

    I then tried to select another sheet tab and then go back to select the calendar, and it worked then.

    So I just added one line of code and I was able to select the calendar right after it was created.

    Hope this can give you some idea or direction to go.

    [VBA]
    Sub scc()
    ActiveSheet.OLEObjects.Add ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150
    Worksheets("Sheet1").Select
    End Sub
    [/VBA]

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    That's perfect! Simply adding ActiveSheet.Select did the trick

    Thanks!

    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address(0, 0) <> "D5" Then Exit Sub
    Application.EnableEvents = False
    With ActiveSheet.OLEObjects.Add(ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150)
    .Name = "CalControl1"
    End With
    ActiveSheet.Select
    Application.EnableEvents = True
    End Sub
    Private Sub CalControl1_Click()
    Range("D5").Value = CalControl1.Value
    Shapes("CalControl1").Delete
    End Sub[/vba]

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Philcjr
    Matt,

    I am no guru, but I tried your code and I could not select the calendar as well.

    I then tried to select another sheet tab and then go back to select the calendar, and it worked then.

    So I just added one line of code and I was able to select the calendar right after it was created.

    Hope this can give you some idea or direction to go.

    [VBA]
    Sub scc()
    ActiveSheet.OLEObjects.Add ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150
    Worksheets("Sheet1").Select
    End Sub
    [/VBA]
    Ditto Matt,[vba]Sub scc()
    ActiveSheet.OLEObjects.Add ClassType:="MSCAL.Calendar", Left:=75, Top:=65, _
    Width:=225, Height:=150
    ActiveSheet.Select
    End Sub[/vba]works fine...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •