PDA

View Full Version : [SOLVED:] Close VBA form



vitorio
11-26-2023, 12:33 PM
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.

Aussiebear
11-26-2023, 12:46 PM
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.

vitorio
11-26-2023, 12:55 PM
Hope to see then. Thanks.

vitorio
11-27-2023, 04:03 AM
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

Aflatoon
11-27-2023, 05:58 AM
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

vitorio
11-27-2023, 03:28 PM
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.

Paul_Hossler
11-27-2023, 04:36 PM
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

vitorio
12-02-2023, 03:31 PM
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!!!

Aussiebear
12-02-2023, 04:16 PM
McGovern?

vitorio
12-02-2023, 04:41 PM
Please remove.

vitorio
12-02-2023, 04:45 PM
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" ...