Consulting

Results 1 to 10 of 10

Thread: Can we access all the WindowsAPI in VBA?

  1. #1
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location

    Post Can we access all the WindowsAPI in VBA?

    Hi,

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

    Regards,
    Krrishna

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    VBA supports APIs, so you should be able to call any of them from VBA.

    What are you trying to do?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    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..

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    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?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    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?.

  8. #8
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    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..

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Regular
    Joined
    Apr 2008
    Posts
    51
    Location
    One thing i am sure is using WindowsAPI we can get the ComboBox in VBA..
    Soon i will paste the code here :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •