VBA代码:Excel范围未正确粘贴到outlook
下面是我的代码,可以粘贴到Outlook的某个范围以发送电子邮件,但它无法正常工作。请帮忙VBA代码:Excel范围未正确粘贴到outlook,excel,vba,outlook,Excel,Vba,Outlook,下面是我的代码,可以粘贴到Outlook的某个范围以发送电子邮件,但它无法正常工作。请帮忙 Private Sub CommandButton1_Click() 'Created by Shenal Salgado Dim xOutApp As Object Dim xOutMail As Object Dim xMailBody As String Dim rng As Range On Error Resume Next Set xOutApp
Private Sub CommandButton1_Click()
'Created by Shenal Salgado
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim rng As Range
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
Set rng = sh_main.Range("A1:E26")
xMailBody = sh_main.Range("A1:E26")
On Error Resume Next
With xOutMail
.To = "xxxxxxxxxx"
.Cc = ""
.BCC = ""
.Subject = "EOD SWAPTION CHECK: " & sh_main.Range("A1")
.Body = xMailBody
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
在大多数情况下,在excel中使用MailEnvelope非常有效 练习此代码,运行它,然后选中outlook发送框
Sub EmAiLtoDave()
'Working in Excel 2002-2013
Dim Sendrng As Range
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sendrng = Range("A1:E26")
Sendrng.Select
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Hi"
With .Item
.To = "SomeBody@Somewhere.com"
.CC = ""
.BCC = ""
.Subject = "EOD SWAPTION CHECK: " & Range("A1")
.Send
End With
End With
End With
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
End Sub
要比“工作不正常”更准确。是否有错误代码和消息,如果有,是哪一行导致了错误?删除错误恢复下一步的
的两个实例。编辑问题以包含任何被隐藏的错误。嗨,奥利,我以前尝试过这种方法,但不断出现以下错误。“运行时错误'1004':对象”“工作簿”“的方法'EnvelopeVisible'失败。我尝试按原样使用您的代码,但得到了相同的错误。-感谢您的回复!很难回答,这里有一个关于从excel发送电子邮件的好链接