I have been trying to replace Sendkeys with Sendmessage but I am having a few problems.

Example of old sendkeys code :

PHP Code:

App
.Activate "Title of other application"
Sendkeys "^o" "~"TRUE
Sendkeys 
"filename" "~"TRUE
DoEvents 
This code seems to work (sometimes)

The Sendmessage code I am using is as follows :

PHP Code:

Public Const WM_SETTEXT = &HC

Private Declare Function GetForegroundWindow _
Lib 
"user32" () As Long

Public Declare Function SetForegroundWindow Lib "user32" _
    
(ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" _
    Alias 
"SendMessageA" _
    
(ByVal hwnd As Long_
    ByVal wMsg 
As Long_
    ByVal wParam 
As Long_
    lParam 
As Any) As Long

SetForegroundWindow otherapp
.hWnd
SendMessage otherapp
.hWndWM_SETTEXT0By Val "^o"
SendMessage GetForegroundWindowWM_SETTEXT0By Val "filename" 
My problem is that using the sendmessage changes the window caption/title of the other application instead of pass in the keystrokes.

What am I doing wrong or should I give up on sendmessage and stick to sendkeys?