Solved

Sendkeys to Outlook - Word Editor

Posted on 2004-08-23
5
562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 18

Assisted Solution

by:bobbit31
bobbit31 earned 250 total points
ID: 11872693
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
ID: 11904827
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
ID: 11967671
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
ID: 12380132
It appears that bobbit31 answered the initial question and I believe I filled in a gap.  I recommend a split.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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