Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sendkeys to Outlook - Word Editor

Posted on 2004-08-23
5
Medium Priority
?
576 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 1000 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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