snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Declare Function MessageBeep& Lib "user32" (ByVal wType As Long)
Public Enum BeepTypes
MB_OK = &H0&
MB_ICONASTERISK = &H40&
MB_ICONEXCLAMATION = &H30&
MB_ICONHAND = &H10&
End Enum
Private Sub CommandButton1_Click()
End Sub
Private Sub Label1_Click()
Label1.TextAlign = fmTextAlignCenter
End Sub
Private Sub Label2_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
'MsgBox ("Return Pressed")
TextBox2.Activate
If Me.TextBox1.text = "" Then
'Label1.Caption = "Please Enter Key!!"
TextBox1.Activate
Else
End If
End If
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If TextBox1.text = TextBox2.text Then
'beep
TestTheBeep1
txt
Label1.Caption = ""
Label3.Visible = False
Label2.Visible = True
TextBox1.text = ""
TextBox2.text = ""
TextBox1.Activate
Else
TestTheBeep2
txt
Me.TextBox2.text = ""
Label1.Caption = ""
Label3.Visible = True
Label2.Visible = False
TextBox2.Activate
End If
Else
End If
End Sub
Public Function BeepType(lSound As BeepTypes) As Long
' Function to return
BeepType = MessageBeep(lSound)
End Function
Sub TestTheBeep1()
' Play the beep
BeepType MB_ICONASTERISK
End Sub
Sub TestTheBeep2()
' Play the beep
BeepType MB_ICONHAND
End Sub
Sub txt()
Dim objFSO, strFolder
Dim txtpass As String
Dim txtfail As String
txtpass = "PASS"
txtfail = "FAIL"
strFolder = "D:\2014"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolder) Then
objFSO.CreateFolder (strFolder)
End If
Open "D:\2014\Test.txt" For Output As #1
If TextBox1.text = TextBox2.text Then
'TextBox2.text = "Pass"
Write #1, Me.TextBox1.text, Me.TextBox2.text, txtpass
Else
'TextBox2.text = "FAIL"
Write #1, Me.TextBox1.text, Me.TextBox2.text, txtfail
End If
Close #1
End Sub