Созданный макрос после определенных действий, по гиперссылке открывает Outlook Express. Поле "Тема" уже заполнено, адреса тоже. Теперь к этому письму нужно прикрепить определенный файл, например D:\Doc1.doc. Отправлять автоматом не нужно. Никак не могу с этим справиться. Еще было бы здорово скопировать в тело письма текстовую строку (именно текст) из определенной ячейки (А1). Пока копирую макросом в буфер а уже руками в Outlook Express вставляю. Как подружить VBA и Outlook Express? Эта проблема в принципе решаема? Спасибо
{quote}{login=Юрий}{date=05.12.2007 02:37}{thema=Как макросом прикрепить файл к письму (Outlook Express)?}{post}Созданный макрос после определенных действий, по гиперссылке открывает Outlook Express. Поле "Тема" уже заполнено, адреса тоже. Теперь к этому письму нужно прикрепить определенный файл, например D:\Doc1.doc. Отправлять автоматом не нужно. Никак не могу с этим справиться. Еще было бы здорово скопировать в тело письма текстовую строку (именно текст) из определенной ячейки (А1). Пока копирую макросом в буфер а уже руками в Outlook Express вставляю. Как подружить VBA и Outlook Express? Эта проблема в принципе решаема? Спасибо{/post}{/quote} Решить это из Excel... честно, я не знаю, возможно ли... сомневаюсь... Разве что с помощью каких-нибдуь API-функций... Из Excel стандартными VBA средствами можно только вызывать диалог отправки письма с прикрепленным файлом открытой книги (на подобие команды Меню-Файл-Отправить-Сообщение как вложение). А с помощью SendKeys можно вставить нужные строки в нужные поля. В принципе можно "извратиться" и через SenKeys и файл прикрепить нужный к сообщению... но это будет не очень надежно.
Подружить же проще и продуктивеней получится только Excel с MS OutLook (не Exress). Это приложения одного пакета и их объектные модели прозрачны друг для друга на уровне VBA. Т.е. можно практически полностью делать все, что умеет OutLook, управляя им из VBA процедур Excel'а.
{quote}{login=Юрий}{date=05.12.2007 02:37}{thema=Как макросом прикрепить файл к письму (Outlook Express)?}{post}Созданный макрос после определенных действий, по гиперссылке открывает Outlook Express. Поле "Тема" уже заполнено, адреса тоже. Теперь к этому письму нужно прикрепить определенный файл, например D:\Doc1.doc. Отправлять автоматом не нужно. Никак не могу с этим справиться. Еще было бы здорово скопировать в тело письма текстовую строку (именно текст) из определенной ячейки (А1). Пока копирую макросом в буфер а уже руками в Outlook Express вставляю. Как подружить VBA и Outlook Express? Эта проблема в принципе решаема? Спасибо{/post}{/quote}
Полгодика назад, я тоже борол такую проблемку. Решение нашел в Инэте.(а вот где не помню) Поищю, потом отпишусь. И кстати - уже был подобный пост на этом форуме
В примере для Access, но думаю подойдет для любой програмы, использующей VBA.
[more=Sending an Outlook Mail Message Programmatically]
Sending an Outlook Mail Message Programmatically Create a sample text file named Customers.txt in the My Documents folder. Start Access, and create a database named Automation.mdb. Note The samples in this article use the Automation.mdb database that is included as a downloadable file with this article. Create a module and type the following line in the Declarations section if it is not already there: Option Explicit
On the Tools menu, click References. In the References box, click to select the Microsoft Outlook 11.0 Object Library, and then click OK. Note If the Microsoft Outlook 11.0 Object Library does not appear in the Available References box, do the following: In Windows Control Panel, double-click Add or Remove Programs. In the list of installed programs, select Microsoft Office 2003, and then click Change. Microsoft Office 2003 Setup starts in maintenance mode. Click Reinstall or Repair, and then click Next. Click Detect and Repair errors in my Office installation, and then click Install. Click OK to close the References dialog box. Type or paste the following VBA procedure in the new module: Код: Sub sbSendMessage(Optional AttachmentPath) Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") ' Create the message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) With objOutlookMsg ' Add the To recipient(s) to the message. Substitute ' your names here. Set objOutlookRecip = .Recipients.Add("Nancy Davolio") objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("Andrew Fuller") objOutlookRecip.Type = olCC ' Set the Subject, Body, and Importance of the message. .Subject = "This is an Automation test with Microsoft Outlook" .Body = "Last test." & vbCrLf & vbCrLf .Importance = olImportanceHigh 'High importance ' Add attachments to the message. If Not IsMissing(AttachmentPath) Then Set objOutlookAttach = .Attachments.Add(AttachmentPath) End If ' Resolve each Recipient's name. For Each objOutlookRecip In .Recipients If Not objOutlookRecip.Resolve Then objOutlookMsg.Display End If End If Next .Send End With Set objOutlookMsg = Nothing Set objOutlook = Nothing Set objOutlookRecip = Nothing Set objOutlookAttach = Nothing ErrorMsgs: If Err.Number = "287" Then MsgBox "You clicked No to the Outlook security warning. " & _ "Rerun the procedure and click Yes to access e-mail" & _ "addresses to send your message. For more information, & _ "see the document at http://www.microsoft.com/office" & _ "/previous/outlook/downloads/security.asp. " " Else Msgbox Err.Number, Err.Description End If End Sub
Note Because of the Outlook E-Mail Security Update, when you run the following procedures, you will be prompted several times for permission to access your e-mail addresses and one prompt to send your message (see the following screen shots). This is expected behavior. For more information, see Security Features for Outlook 2002 and Previous Versions.
Prompt 1. Prompt to access e-mail addresses
Prompt 2. Prompt to send e-mail message
To test this procedure, type the following line in the Immediate window in the Visual Basic Editor, and then press ENTER: sbSendMessage "C:\Documents and Settings\UserName\My Documents\Customers.txt"
Цитата:------------------------------------------------- "На сайте Ron de Bruin, специалиста из Нидерландов, можно найти несколько полезных надстроек для отправки книг и листов Excel по эл.почте и удобную надстройку для фильтрации с богатыми возможностями."