PDA

View Full Version : Can we access all the WindowsAPI in VBA?



gopi09_m
09-07-2008, 06:02 AM
Hi,

How do i know whether a particular API supports in VBA.so that i can call the functions available in it?

Regards,
Krrishna

Bob Phillips
09-07-2008, 06:08 AM
VBA supports APIs, so you should be able to call any of them from VBA.

What are you trying to do?

gopi09_m
09-07-2008, 06:23 AM
My requirement is to display a combo box with five colors lets say Red,Blue,Green,White and Yellow.When user selects one of them it should display the selected color.I guess we can use user32.dll but dont know how to access the function to create a combo box...

ComboBox Items: Red,Blue,Green,White and Yellow
Combobox name: ComboBox1

any help would be appreciated..

Bob Phillips
09-07-2008, 06:25 AM
Comboboxes have nothing to do with APIs, you have 4 ways to create them, Data Validation, Forms controls, ActiveX controls, or a userform. So what is the question re APIs?

gopi09_m
09-07-2008, 06:33 AM
Yes using Data Validation, Forms controls, ActiveX controls, or a userform is one side of the coin.but i want to implement it with user32.dll or some other WinodwsAPI..

can it be done?

Bob Phillips
09-07-2008, 06:49 AM
Yeah but you are not saying why, or how, you just keep repeating that you want to us an API. Unless you explain yourself, there is no help that we can offer.

gopi09_m
09-07-2008, 07:23 AM
The above requirement once implemented i want to use with QTP tool .this tool provides the minimal interfaces such as edit box but not combo box.
whereas in my project mostly i have few choices from which i will ask user to select.so this can be easily implemented with combo box.

whatever the code that is implemented with VBA can be run with the above tool.that tool doesnt have support for creating Data Validation, Forms controls, ActiveX controls, or a userform.

but the only good thing we have with the tool is we can implement the calls to API.

hope you understand my requirement now?.

gopi09_m
09-07-2008, 07:32 AM
i have the following piece of code which gets the windows directory path.And i have implemented the same with the QTP tool and Execl VBA.
both are successfull.

Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Sub sub123()

Dim TheResult
Dim TheWindowsDirectory As String
TheWindowsDirectory = Space(144)
'Fill 144 spaces in TheWindowsDirectory string
TheResult = GetWindowsDirectory(TheWindowsDirectory, 144)
'Get path and place it in TheResult string
If TheResult = 0 Then
MsgBox "Cannot get the Windows Directory"
Else
'Prepare the String for preview, and then display in a Message Box
TheWindowsDirectory = Trim(TheWindowsDirectory)
MsgBox "The Windows Path: " & TheWindowsDirectory
End If
End Sub

In the same way i am looking out for a function that creates the combobox with the required items..

Bob Phillips
09-07-2008, 08:16 AM
The windows path is simple because it is a piece of system information, which an API can query very easily. Similalrly, window attributes, such as caption bars, can be interrogated via an API, but a combobox is a control that a product supports (or doesn't). You can't just create one with an API for a product that doesn't have one. You might be able to create a custom ActiveX control that behaves like the familiar comboboxes, but it would be a lot of work, and I have no idea whether that tool will support ciustom controls, somehow I doubt it.

gopi09_m
09-07-2008, 08:43 AM
One thing i am sure is using WindowsAPI we can get the ComboBox in VBA..
Soon i will paste the code here :-)