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:)
Printable View
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:)
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. :)
im trying to use sendmessage to a textbox on a worksheet do you think that should work.
VB Code:
Option Explicit 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 Private Const EM_SETTABSTOPS = &HCB 'in a different sub Dim tabstop As Long tabstop = 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
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! :(
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:)
well i got it to do what i wanted and here is the source code
VB Code:
Do While True lngEnterPos1 = InStr(intStart, Sheets("ECNFile").txtbox1.Text, Chr(13) & Chr(10)) If (lngEnterPos1 > lngTabPos) Then lngEnterPos1 = lngEnterPos2 Exit Do End If lngEnterPos2 = lngEnterPos1 intStart = lngEnterPos1 + 1 Loop curpos1 = lngTabPos - (lngEnterPos1 + 2)
thanks for your help workhorse:)