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