Solved

Sendkeys to Outlook - Word Editor

Posted on 2004-08-23
5
556 Views
Last Modified: 2012-06-27
Using VB Pro 6.0

I am trying to wite a VB app that will paste an address into the [To:] field of a new mail message.

Outlook is using Word editor.

When I use [Sendkeys "mailaddr@company.com", True"] command to notepad it works everytime.

When I use [Sendkeys "mailaddr@company.com", True"] command to Outlook it only works occasionally.

Any ideas?  Any alternatives to using sendkeys?

Thanks.
0
Comment
Question by:Packerland
  • 2
5 Comments
 
LVL 18

Assisted Solution

by:bobbit31
bobbit31 earned 250 total points
Comment Utility
use FindWindow and SendMessage API:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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("rctrl_renwnd32", "Untitled - Message (Plain Text) ") '' <-- replace 'Untitled - ... ' w/ the title of the compose mail window
    afxhwnd = FindWindowEx(hwnd, 0, "AfxWnd", vbNullString)
    dlghwnd = FindWindowEx(afxhwnd, 0, "#32770", vbNullString)
    editHwnd = FindWindowEx(dlghwnd, 0, "RichEdit20A", vbNullString)

    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
0
 

Author Comment

by:Packerland
Comment Utility
Bobbit,

Problem is that I don't know what the window name might be.  If it is a new message then the name is static but if it is forwarded or replied to then the Window name is the subject of the message.

Is there anyway to get a list of all of the Open windows?
0
 
LVL 3

Accepted Solution

by:
aParser earned 250 total points
Comment Utility
Enumerate All Open Windows (Parent and Children)
http://www.freevbcode.com/ShowCode.Asp?ID=701

I also found something at http://www.mvps.org/access/api/api0051.htm which contains this loop:

  '   Start with the first child of the Desktop window
  hWnd = apiGetWindow(apiGetDesktopWindow(), GW_CHILD)
  '   Enumerate all open windows
  Do While Not hWnd = 0
    ...
    hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
  Loop

The page gives the actual Declares for the APIs.
0
 
LVL 3

Expert Comment

by:aParser
Comment Utility
It appears that bobbit31 answered the initial question and I believe I filled in a gap.  I recommend a split.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now