英文:
put text body above the pasted range
问题
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "这是邮件正文:" ' & vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
MyRange.Copy
doc.Range(x, x).Paste
.To = Range("I3").Value
.Subject = "我的主题"
Application.CutCopyMode = 0
End With
End Sub
英文:
i have a code below that paste a range into an email body but my problem is the text body This is the body: is below the pasted range when the code is ran, maybe someone can help how to put it above the pasted range
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "This is the body:" '& vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
MyRange.Copy
doc.Range(x, x).Paste
.To = Range("I3").Value
.Subject = "My subject"
Application.CutCopyMode = 0
End With
End Sub
答案1
得分: 1
以下是翻译后的代码部分:
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "This is the body:" '& vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
x = doc.Range.End - 1
MyRange.Copy
doc.Range(x).Paste
.To = Range("I3").Value
.Subject = "My subject"
Application.CutCopyMode = 0
End With
End Sub
Add more lines to bottom of body
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "This is the body:" '& vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
x = doc.Range.End - 1
MyRange.Copy
doc.Range(x).Paste
x = doc.Range.End - 1
doc.Range(x) = "More Stuff" 'add more stuff
x = doc.Range.End - 1
doc.Range(x) = vbNewLine & "Even More Stuff" 'add more stuff with New line
x = doc.Range.End - 1
doc.Range(x) = vbNewLine & vbNewLine & vbNewLine & _
"Even More Stuff" 'add more stuff with multi-line breaks
.To = Range("I3").Value
.Subject = "My subject"
Application.CutCopyMode = 0
End With
End Sub
希望这对你有所帮助。如果需要更多信息或翻译,请随时告诉我。
英文:
You may need to set x before you paste.
x = doc.Range.End - 1
finds the end of the document less 1
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "This is the body:" '& vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
x = doc.Range.End - 1
MyRange.Copy
doc.Range(x).Paste
.To = Range("I3").Value
.Subject = "My subject"
Application.CutCopyMode = 0
End With
End Sub
Add more lines to bottom of body
Sub SendEmailWithRange()
Dim MyRange As Range
Dim doc As Object
Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
With CreateObject("outlook.application").CreateItem(0)
.Display 'Change to .Send to send the email immediately
.Body = "This is the body:" '& vbNewLine & vbNewLine
Set doc = .GetInspector.WordEditor
x = doc.Range.End - 1
MyRange.Copy
doc.Range(x).Paste
x = doc.Range.End - 1
doc.Range(x) = "More Stuff" 'add more stuff
x = doc.Range.End - 1
doc.Range(x) = vbNewLine & "Even More Stuff" 'add more stuff with New line
x = doc.Range.End - 1
doc.Range(x) = vbNewLine & vbNewLine & vbNewLine & _
"Even More Stuff" 'add more stuff with multi-line breaks
.To = Range("I3").Value
.Subject = "My subject"
Application.CutCopyMode = 0
End With
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论