The following is the vb code and working well with VB6 project. But when I am using the same with Excel VBA userform and not working.
This is the VBA code:Code:Option Explicit 'Start a new Standard-EXE project. 'Add a textbox and a listbox control to form 1 'Add the following code to form1: Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As String, lParam As Any) As Long Const LB_FINDSTRING = &H18F Private Sub Form_Load() With List1 .Clear .AddItem "RAM" .AddItem "rams" .AddItem "RAMBO" .AddItem "ROM" .AddItem "Roma" .AddItem "Rome" .AddItem "Rommel" .AddItem "Cache" .AddItem "Cash" End With End Sub Private Sub Text1_Change() List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, Text1, ByVal Text1.Text) End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text1.Text = List1.Text End If End Sub
The error is coming here at this line:Code:Option Explicit Private Sub TextBox1_Change() ListBox1.ListIndex = SendMessage(ListBox1.hWnd, LB_FINDSTRING, TextBox1, ByVal TextBox1.Text) End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii = 13 Then TextBox1.Text = ListBox1.Text End If End Sub Private Sub UserForm_Initialize() With ListBox1 .Clear .AddItem "RAM" .AddItem "rams" .AddItem "RAMBO" .AddItem "ROM" .AddItem "Roma" .AddItem "Rome" .AddItem "Rommel" .AddItem "Cache" .AddItem "Cash" End With End Sub
As Compile error : Metheod or data member not found. For this ListBox1.hWndCode:ListBox1.ListIndex = SendMessage(ListBox1.hWnd, LB_FINDSTRING, TextBox1, ByVal TextBox1.Text)
In VB6, THE List1.hwnd property is available but in VBA Listbox1.hwnd is not coming.
How can I modify it to use with Excel VBA user form<




Reply With Quote