API Error

Yonnga

New Member
Joined
Mar 30, 2005
Messages
9
Hi all,

I have written small program with VBA in Excel, and try to use API function - "SendMessage". However, I do not know why generate error message - "Complie Error: method or data member not found" when the program is running. Could anybody help me to solve it. Below statements I wrote as:

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As _
Long, lParam As Long) As Long



Private Sub ComboBox1_Change()

Const CB_SHOWDROPDOWN = &H14F
Dim Tmp
Tmp = SendMessage(ComboBox1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)

'Compile error: method or data member not found
End Sub

Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
.AddItem "G"
End With

End Sub


Thanks in advance.

Yonnga
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,912
Office Version
  1. 365
Platform
  1. Windows
Yonnga

Where is this code located?

PS What are you using the API call for?
 

Yonnga

New Member
Joined
Mar 30, 2005
Messages
9
Norie,

Thanks for your attention.

All codes I placed in the userform with a Combobox. The API is built-in function in Windows system, so it is ready for using any time by Window's user.

Yonna
 

jwhite100

New Member
Joined
Sep 23, 2005
Messages
20
Re API

Unfortunately you can't do much with handles to controls in VBA, but you achieve the same thing with this code.

Code:
Private Sub ComboBox1_Change()
ComboBox1.DropDown
End Sub
 
L

Legacy 98055

Guest
ComboBox1.hwnd

There is no such property in a MSForms combobox.

Unfortunately, the combobox is a virtual or windowless control within VBA. This being so, there is not a window handle. However, there is a "Dropdown" method to compensate for this in your case.

<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> ComboBox1_Change()
       ComboBox1.DropDown
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> UserForm_Initialize()
       <font color="#0000A0">With</font> ComboBox1
           .AddItem "A"
           .AddItem "B"
           .AddItem "C"
           .AddItem "D"
           .AddItem "E"
           .AddItem "F"
           .AddItem "G"
       <font color="#0000A0">End</font> <font color="#0000A0">With</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("10520062431375").value=document.all("10520062431375").value.replace(/<br \/>\s\s/g,"");document.all("10520062431375").value=document.all("10520062431375").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("10520062431375").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="10520062431375" wrap="virtual">
Private Sub ComboBox1_Change()
ComboBox1.DropDown
End Sub

Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
.AddItem "G"
End With
End Sub</textarea>[/b]
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,912
Office Version
  1. 365
Platform
  1. Windows
The API is built-in function in Windows system
Yonna

I know what the Windows API is.:)

I was just wondering what you were using it for.

Anyway, looks as though Tom's got you covered.
 

Watch MrExcel Video

Forum statistics

Threads
1,112,883
Messages
5,543,019
Members
410,583
Latest member
gazz57
Top