放置文本主体在粘贴的范围之上。

huangapple go评论57阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月19日 11:58:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定