Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Close a form automatically

    I am using the calandar form in a spreadsheet to enter dates. After I select a date I want the calendar to close automatically so I dont have to click on the X to close it.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Rick,

    Welcome to the lounge as a poster.

    You might try formname.Close in the OnClick event.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    rickc2591 (2011-12-18)

  4. #3
    New Lounger
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you for the help. I'm not sure where to place the code. Here is the code for the calendar.



    Private Sub Calendar1_Click()

    ActiveCell = Calendar1.Value

    ActiveCell.NumberFormat = "mm/dd/yy"

    End Sub



    Private Sub UserForm_Activate()

    Me.Calendar1.Value = Date

    End Sub

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Rick,

    Code:
    Private Sub Calendar1_Click()
    
    ActiveCell = Calendar1.Value
    
        ActiveCell.NumberFormat = "mm/dd/yy"
    
    Me.close   '*** Or userformname.close ***
    
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. The Following User Says Thank You to RetiredGeek For This Useful Post:

    rickc2591 (2011-12-18)

  7. #5
    New Lounger
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It now give me errors when I run the code. Doesn't seem to like the .close part (says "doesn't support .close"). I am using excel 2007 if this helps.

  8. #6
    New Lounger
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Here is a sample sheet if it helps.

    Calendar.xls

  9. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Rick,

    Sorry about that. The Hide property takes care of the problem.
    Attached Files Attached Files
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  10. #8
    New Lounger
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much. I am still new to VBA code and I just couldn't find what I needed. Works just like I want it to.

  11. #9
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    It's:
    Code:
    Unload Me
    if you want to unload it rather than simply hide it, BTW.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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