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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Yonnga

Where is this code located?

PS What are you using the API call for?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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]
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top