问题描述
我有一个报告,我想通过excel发送。它将包括收件人,主题和身体中的信息。实际上它可以复制有问题的单元格。
到目前为止,我创建了一个按钮,并使用此代码为其分配一个宏:
Private Sub CommandButton1_Click ()
Application.Dialogs(xlDialogSendMail).Show arg1:= Sheets(Sheet1)。Range(E3),_
arg2:= Sheets(Sheet1)。Range )
End Sub
问题是这个命令发送工作簿作为附件。
有人可以帮助我的代码,让我这样做。
谢谢百万!
欢呼
设置对Microsoft Outlook xx.x对象库,您可以使用此代码作为构建或发送电子邮件的一个示例:
因为它将只显示电子邮件不发送。您可以注释掉.display行并取消注释.send以发送它。
Sub EmailFromExcel()
On Error GoTo PROC_EXIT
Dim OL As New Outlook.Application
Dim olMail As Outlook.MailItem
设置olMail = OL.CreateItem(olMailItem)
Dim SrcSheet As Excel.Worksheet
Set SrcSheet = Sheets(Sheet1)
使用olMail
.To = SrcSheet.Range(E3)。文本
.Subject = SrcSheet.Range(E7)。Text
.Body = SrcSheet.Range(E12)。Text
.Display vbModal
'.Send
End With
PROC_EXIT:
错误转到0
OL.Quit
设置OL =没有
结束Sub
i have a report that i would like to send via excel.it will include the recipitents, subject and the information in the body. actually it could copy the cells in question.what i did so far is create a button and assign a macro to it with this code:
Private Sub CommandButton1_Click()
Application.Dialogs(xlDialogSendMail).Show arg1:=Sheets("Sheet1").Range("E3"), _
arg2:=Sheets("Sheet1").Range("E7")
End Sub
the problem is that this command sends the workbook as attachment.
can someone help me with the code that will allow me to do this.
thanks a million!
cheers
Set a reference to the "Microsoft Outlook xx.x Object Library" and you can use this code as an example of what to do to build or send an email:
As it is it will just display the email without sending. You can comment out the .display line and uncomment the .send to just send it.
Sub EmailFromExcel()
On Error GoTo PROC_EXIT
Dim OL As New Outlook.Application
Dim olMail As Outlook.MailItem
Set olMail = OL.CreateItem(olMailItem)
Dim SrcSheet As Excel.Worksheet
Set SrcSheet = Sheets("Sheet1")
With olMail
.To = SrcSheet.Range("E3").Text
.Subject = SrcSheet.Range("E7").Text
.Body = SrcSheet.Range("E12").Text
.Display vbModal
'.Send
End With
PROC_EXIT:
On Error GoTo 0
OL.Quit
Set OL = Nothing
End Sub
这篇关于Excel宏发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!