Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSend an Outlook Express attachment
KeywordsOutlook Express, email, e-mail, attachment, ShellExecute, FindWindow
CategoriesAPI, Office, Software Engineering, Tips and Tricks
 
Thanks to Neil Crosby

This program requires Outlook Express to be your default e-mail program.

The program uses ShellExecute to start sending an email with Outlook, filling in the message's To, Subject, and Body fields.

It then uses FindWindow to find a window with title equal to the mail message's Subject (that's the title Outlook Express gives the new mail window). It loops until it finds this window.

Next the program uses SendKeys to send the new window the keys Alt-I-A. That invokes the Isert menu's File Attachment command. The program adds the zip file's name, sends two tabs to move to the Attach button, and sends Enter to trigger the button.

 
Private Sub Command1_Click()
Dim zip_file As String, Ret As Long

    ' Start Outlook Express email.
    zip_file = App.Path & "\test.zip"
    ShellExecute Me.hWnd, "Open", _
        "mailto:Anyone@anywhere.com?subject=" & zip_file & _
        "&body=Zip File Attached", vbNullString, _
        vbNullString, vbNormalFocus

    ' Wait until Outlook Express is ready.
    While Ret = 0
        DoEvents
        Ret = FindWindow(vbNullString, zip_file)
    Wend

    ' Send keys Alt-I-A, the zip file name,
    ' two TABs, and Enter.
    SendKeys "%ia" & zip_file & "{TAB}{TAB}{ENTER}"
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated