P
Pascal
Guest
Bonjour à tous sur le forum,
Pour mon petit projet, j'aurais besoin de textbox avec prop. multiline et enterkeybehavior à true, mais qui ne permettent pas d'écrire sur plus de quelques lignes.
J'ai trouvé sur le net (http://blackbeltvb.com) une source utilisant un appel API (dont je ne connais rien) et qui correspond à ce que je recherche:
Textbox1 pour le texte, Textbox2 pour nb caractères maxi/lignes, Textbox3 pour nb maxi de lignes.
Seulement, lorsque je lance mon Userform, j'ai une erreur:
"Erreur de compilation: Membre de méthode ou de données introuvable" avec focus sur l'argument "hwnd" de la ligne "i=SendMessage(....." ??
Est-ce normal ?? est-il impossible d'appeler ce genre API avec excel ? ou bien est-ce une erreur de ma part ou pb config excel ?
(Mon poste; Excel 2000 , Window XP Pro)
Peut être est-il possible d'arriver au même résultat sans passer par une API?
Je laisse le code source ci dessous:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Sub Text1_Change()
Static bInHere As Boolean, txt As String, iSel As Long, iSelLen As Long
If bInHere Then Exit Sub
bInHere = True
Dim iPerLine As Long, aBuf$, i As Long, iRet As Long
iPerLine = Val(Text2.Text)
aBuf$ = Chr$(0) & Chr$(255) & Space$(253)
i = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, ByVal 0)
iRet = SendMessage(Text1.hwnd, EM_GETLINE, 1, ByVal aBuf$)
If iRet > iPerLine Then
Text1.Text = txt
Text1.SelStart = iSel
Text1.SelLength = iSelLen
Else
txt = Text1.Text
iSel = Text1.SelStart
iSelLen = Text1.SelLength
End If
bInHere = False
End Sub
Private Sub Text1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim iLines As Long
iLines = Val(Text3.Text)
Select Case KeyAscii
Case 13
If SendMessage(Text1, EM_GETLINECOUNT, 0, ByVal 0) + 1 > iLines Then KeyAscii = 0
End Select
End Sub
Vous remerciant par avance,
Bonne journée à tous,
Pascal
Pour mon petit projet, j'aurais besoin de textbox avec prop. multiline et enterkeybehavior à true, mais qui ne permettent pas d'écrire sur plus de quelques lignes.
J'ai trouvé sur le net (http://blackbeltvb.com) une source utilisant un appel API (dont je ne connais rien) et qui correspond à ce que je recherche:
Textbox1 pour le texte, Textbox2 pour nb caractères maxi/lignes, Textbox3 pour nb maxi de lignes.
Seulement, lorsque je lance mon Userform, j'ai une erreur:
"Erreur de compilation: Membre de méthode ou de données introuvable" avec focus sur l'argument "hwnd" de la ligne "i=SendMessage(....." ??
Est-ce normal ?? est-il impossible d'appeler ce genre API avec excel ? ou bien est-ce une erreur de ma part ou pb config excel ?
(Mon poste; Excel 2000 , Window XP Pro)
Peut être est-il possible d'arriver au même résultat sans passer par une API?
Je laisse le code source ci dessous:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Sub Text1_Change()
Static bInHere As Boolean, txt As String, iSel As Long, iSelLen As Long
If bInHere Then Exit Sub
bInHere = True
Dim iPerLine As Long, aBuf$, i As Long, iRet As Long
iPerLine = Val(Text2.Text)
aBuf$ = Chr$(0) & Chr$(255) & Space$(253)
i = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, ByVal 0)
iRet = SendMessage(Text1.hwnd, EM_GETLINE, 1, ByVal aBuf$)
If iRet > iPerLine Then
Text1.Text = txt
Text1.SelStart = iSel
Text1.SelLength = iSelLen
Else
txt = Text1.Text
iSel = Text1.SelStart
iSelLen = Text1.SelLength
End If
bInHere = False
End Sub
Private Sub Text1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim iLines As Long
iLines = Val(Text3.Text)
Select Case KeyAscii
Case 13
If SendMessage(Text1, EM_GETLINECOUNT, 0, ByVal 0) + 1 > iLines Then KeyAscii = 0
End Select
End Sub
Vous remerciant par avance,
Bonne journée à tous,
Pascal