sendkeys to active window
Hi,
Does anyone have any idea why this only work in design and not from the exe ?
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Sub RSPaste()
Dim sClipboardData As String
Dim iHwnd As Long
sClipboardData = Clipboard.GetText()
Clipboard.Clear
If sClipboardData <> vbNullString Then
Clipboard.SetText "wooo" & sClipboardData
Else
Clipboard.SetText "hoooo"
End If
iHwnd = FindWindowWild("*Visual Basic*", False)
If iHwnd <> 0 Then
SetForegroundWindow iHwnd
SendKeys ("^v")
End If
End Sub
Re: sendkeys to active window
Because its not finding the window like on this line - iHwnd = FindWindowWild("*Visual Basic*", False).
The function is not declared. Depending on how you have your error handling in VB it should be generating
an error, but since it can not find the window it just sends the keys to the active window VB. Also,
I dont think that the asterisks work as wild card chars. So it is actually looking for a window "*Visual Basic*"
HTH
Re: sendkeys to active window
the FindWindowWild is declared in loacation, and it does find the proper window. but it still only works on VB and not by using the EXE...
Re: sendkeys to active window
I noticed that you used Sendkeys ("^v")
I use it this way...
Sendkeys "^(v)"
Maybe it's that.