|
Salem さん
以前、こちらの常連さんのJuJuさんに教えてもらったコードですが、
'*************************************
Private Sub txtTest_Change()
txtTest.Text = fncLeftA(txtTest.Text, txtTest.MaxLength)
End Sub
'==============================================
Private Sub txtTest_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With txtTest
If fncLenA(.Text & ChrW$(KeyAscii)) > .MaxLength Then
KeyAscii = 0
End If
End With
End Sub
'==============================================
Private Function fncLeftA(ByVal szWord As String, ByVal lLength As Long) As String
'szWord=テキストボックスに入力された文字列
'lLength=テキストボックスに設定された制限文字数
fncLeftA = StrConv((LeftB(StrConv(szWord, vbFromUnicode), lLength)), vbUnicode)
If fncLeftA <> Left$(szWord, Len(fncLeftA)) Then
fncLeftA = Left$(szWord, Len(fncLeftA) - 1)
End If
End Function
'==============================================
Private Function fncLenA(ByVal szWord As String) As Long
fncLenA = LenB(StrConv(szWord, vbFromUnicode))
End Function
'*************************************
こんな感じです。
|
|