kids Alphabets Learning in Excel VBA Userform
ฝัง
- เผยแพร่เมื่อ 19 ธ.ค. 2024
- Display pressed keyboard keys (Alphabets) in userform.
----------------------------------------Source code----------------------------------------------------------
' Declare for precise time delay
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
' Declare the speech object
Dim Speech As Object
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
' Check if the key pressed is a letter (A-Z)
If KeyCode "angled bracket1"= 65 And KeyCode "angled bracket2"= 90 Then
Dim PressedKey As String
PressedKey = Chr(KeyCode)
Me.Label1.Caption = PressedKey
' Speak the pressed key
Speech.Speak PressedKey
' Animate the label with color changes
AnimateLabel
Me.TextBox1.Text = ""
End If
Me.TextBox1.Text = ""
End Sub
Private Sub UserForm_Initialize()
' Initialize speech and set form appearance
Set Speech = CreateObject("SAPI.SpVoice")
Me.Label1.Font.Size = 200
Me.TextBox1.SetFocus
End Sub
Private Sub UserForm_Terminate()
' Release the speech object
Set Speech = Nothing
End Sub
' Simple label animation (color flash)
Sub AnimateLabel()
Dim i As Integer
For i = 1 To 3
Me.Label1.ForeColor = RGB(255, 0, 0) ' Red
DoEvents
Sleep 200 ' 200 milliseconds delay
Me.Label1.ForeColor = RGB(0, 0, 255) ' Blue
DoEvents
Sleep 200 ' 200 milliseconds delay
Next i
End Sub
---------------------------------------------module1---------------------------------------
Sub Button1_Click()
UserForm1.Show
End Sub