Results 1 to 6 of 6

Thread: Win32 Api *resolved- code i used inside*

  1. #1

    Thread Starter
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195

    Win32 Api *resolved- code i used inside*

    i was wondering if you can use win32 api or user32 api in VBA i cant seem to get some things to work that i was trying to do and it made me think, does VBA allow the use of API. well thanks for the help
    Last edited by big_k105; Oct 30th, 2003 at 05:10 PM.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Yep. You can use API in VBA. Same as VB. The VBA Forms 2.0 controls don't have window handles though, so APIs won't always wok if you are trying to manipulate controls on a UserForm.

  3. #3

    Thread Starter
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    im trying to use sendmessage to a textbox on a worksheet do you think that should work.

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3. Private Const EM_SETTABSTOPS = &HCB
    4.  
    5. 'in a different sub
    6.         Dim tabstop As Long
    7.         tabstop = 8
    8.         SendMessage Sheets("ECNFile").txtbox1.hwnd, EM_SETTABSTOPS, 1, tabstop


    this is te code that im using the SendMessage line gets an error i cant remember what the error is off hand but i will check when i get back to work tomorrow.

    thanks for the help workhorse

  4. #4
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    I would expect you get "Object doesn't support this method" because txtbox1 doesn't have an hWnd. No window handles for Forms 2.0 controls. Don't ask me why. If you map all hWnds, you will find that you get down to a container with the controls, but no hWnds for the controls inside the container. Without an hWnd, I know of no way to SendMessage (or any other API that requires an hWnd) to a Forms 2.0 control. It's not for a lack of trying. If you find way, post it!

  5. #5

    Thread Starter
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    well i cant seem to get it to work either. i will keep trying but i was wondering if you knew of a different way to set tab stops for a textbox in the worksheets thanks dude

  6. #6

    Thread Starter
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    well i got it to do what i wanted and here is the source code

    VB Code:
    1. Do While True
    2.                 lngEnterPos1 = InStr(intStart, Sheets("ECNFile").txtbox1.Text, Chr(13) & Chr(10))
    3.                 If (lngEnterPos1 > lngTabPos) Then
    4.                     lngEnterPos1 = lngEnterPos2
    5.                     Exit Do
    6.                 End If
    7.                 lngEnterPos2 = lngEnterPos1
    8.                 intStart = lngEnterPos1 + 1
    9.             Loop
    10.  
    11.             curpos1 = lngTabPos - (lngEnterPos1 + 2)

    thanks for your help workhorse

Posting Permissions

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



Click Here to Expand Forum to Full Width