Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / General MS Word Questions / December 2003

Tip: Looking for answers? Try searching our database.

Emailing a Word Document through Outlook using VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Adams - 17 Dec 2003 03:20 GMT
I'm a novice trying to do a little VBA.  I'm stumped as
to why one SendKey command will not work.  Please take a
look at my code below.  Do I have to activate Outlook
even though it appears to be activated by Word?  Then
within Outlook add some kind of document send command?  
Thanks very much!!!

'This is a macro in Word.  Once the word document
'is finished and the macro run, the macro opens up
'an email in the default email handler, Outlook. Word
'2000, Windows 2000, and Outlook 2000.
'The objective of the program is for the user to start
'this macro when the Word document is finished.  Then the
'document is instantly emailed to the correct addressee.
'But alas, the "Send" line doesn't work!

   ActiveDocument.SendMail 'opens up Outlook, Word still
'open.
   

   ThreeSeconds = 3 'creates a three second pause
   StartTime = Timer
   Do While Timer < StartTime + ThreeSeconds
   DoEvents  'just in case
   Loop

   SendKeys ("fia-MidlandCourt@michigan.gov") 'this
'should send the correct address to the "To:" field.
'The word document seems properly attached to the Outlook
'email, now address and ready to send.

   ThreeSeconds = 3
   StartTime = Timer
   Do While Timer < StartTime + ThreeSeconds
   DoEvents  'just in case  
   Loop

   SendKeys ("%(f)") 'Opens up the "file" menu in
'Microsolf Outlook 2000
   

   ThreeSeconds = 3
   StartTime = Timer
   Do While Timer < StartTime + ThreeSeconds
   DoEvents  'just in case
   Loop

   SendKeys "(e)" 'selects the "Send" item in the "file"
'menu.
   

   ThreeSeconds = 3
   StartTime = Timer
   Do While Timer < StartTime + ThreeSeconds
   DoEvents  'just in case
   Loop

   
   SendKeys ("^~") '"Send" menu item in Outlook says
'Control Enter is the keyboard shortcut for sending a
'message.  But it doesn't work.  When this is executed,
'the message moves down to the task bar.  If it is
'retrieved, the message displays, "This message has not
'been sent."  During the macro execution presssing Enter,
'or control enter, will appropriately send the
'message. Why won't the macro commands execute properly?

   
   ThreeSeconds = 3
   StartTime = Timer
   Do While Timer < StartTime + ThreeSeconds
   DoEvents  'just in case
   Loop

   
   MsgBox ("Orders have been sent to FIA!") 'This works
   
   
   
End Sub
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 17 Dec 2003 04:36 GMT
Hi Robert,

See the article "How to send an email from Word using VBA" at:

http://www.mvps.org/word/FAQs/InterDev/SendMail.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
> I'm a novice trying to do a little VBA.  I'm stumped as
> to why one SendKey command will not work.  Please take a
[quoted text clipped - 68 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.