Consulting

Results 1 to 11 of 11

Thread: Close VBA form

  1. #1

    Close VBA form

    Enclosed Excel macro file (CalendarFormHelp.xlms).


    I will like that after pressed de X button in the form, the form closed, without entering any date.


    Leaving the cell C7 empty.


    Just without entering any date (just empty).


    Is this possible?


    Thanks for the suggestion.
    Attached Files Attached Files

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,190
    Location
    Welcome to VBAX Vitorio. I notice that two of the contributors to the Calender form are Graham Mayor and Greg Maxey, both are active members here. One or both could be along shortly.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Hope to see then. Thanks.

  4. #4
    File in first post.
    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Thanks to Dan McGovern for suggesting and supplying this code
    Dim TriggerCells As Range
    ' The cells you click in to display the calendar
        Set TriggerCells = Range("C7")
    If Not Intersect(TriggerCells, Target) Is Nothing Then
    ActiveCell.value = CalendarForm.GetDate(FirstDayOfWeek:=Monday, SaturdayFontColor:=RGB(250, 0, 0), SundayFontColor:=RGB(250, 0, 0))
    End If
    End Sub
    Maybe something like this:

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    '    If CloseMode = 0 Then
    '        Cancel = True
    '        DateOut = SelectedDateIn
    '        Me.Hide
    '    End If
    'End Sub
    Last edited by Aussiebear; 11-27-2023 at 01:23 PM. Reason: Corrected the code tags

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,745
    Location
    If you just want to leave it as it is:

        If Not Intersect(TriggerCells, Target) Is Nothing Then      Dim SelectedDate As Date
            SelectedDate = CalendarForm.GetDate(FirstDayOfWeek:=Monday, SaturdayFontColor:=RGB(250, 0, 0), SundayFontColor:=RGB(250, 0, 0))
            If SelectedDate <> 0 Then ActiveCell.value = SelectedDate
        End If
    Be as you wish to seem

  6. #6
    This week I am going to test the recommendations made, since I am out of town. As soon as finish I will le you know the results.

    Thanks to all for your help.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,748
    Location
    You can use the QueryClose event to pass a global variable when you click on the [X] that says to clear the cell

    Search for bClearDate in the code



    Public bClearDate As Boolean    '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    
    
        If CloseMode = 0 Then
            Cancel = True
            bClearDate = True   '   <<<<<<<<<<<<<<<<<<
            Me.Hide
            Unload Me
        End If
    
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Just return this week.

    Tested the recommended recommendations. Thanks to all for the help provided , specially for McGovern for answer the special request to help.

    Solutions provided solved my request.

    Until the next time!!!

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,190
    Location
    McGovern?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    Please remove.

  11. #11
    From above post, #4



    "Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Thanks to Dan McGovern for suggesting and supplying this code
    Dim TriggerCells As Range" ...

Posting Permissions

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