jfyfe
asked on
copying string from a variable into notepad
Hi, i have shelled notepad and am trying to find the best way to copy string data from a variable to notepad. I can use Sendkeys, but thought there was a better way.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick replys!
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 Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim hwnd As Long
Dim stringToSend As String
hwnd = FindWindow("Notepad", vbNullString)
editHwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString)
MsgBox editHwnd
If editHwnd > 0 Then '' found the textbox so send the text
stringToSend = "Hello World!"
SendMessage editHwnd, WM_SETTEXT, 256, ByVal stringToSend
End If
End Sub
'' NOTE, that you should send the string ByVal