查找“回车"在邮件正文中 [英] Find "carriage return" in a mail.body

查看:22
本文介绍了查找“回车"在邮件正文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的邮件:

你好

请注意,我们在 16 点 15 分...

Please note we did ... at 16h15

已完成的操作:重建等

真诚的

先生

每封邮件中的操作都会发生变化,我想要的是将操作插入到我的 Excel 中.问题是我不知道如何获得回车"(如果这是正确的名字,这就是 traduction 给我的).我在互联网上发现 vbLfChr(10) 是回车".我试图找到开头:

The actions change in every mail and what I want is to insert the action in my Excel. The problem is that I don't know how to get the "carriage return" (idk if this is the right name, this is what traduction gave me). What I find in internet is that vbLfChr(10) is the "carriage return". What I tried is to find the beginning :

TechnicPosition= InStr(1, .Body, "Actions done: ")
TechnicAction= Mid(.Body, TechnicPosition, 14) ' first char from the action

但我无法获得最后一个字符(来自 TechnicAction 的第一个回车").我尝试了很多事情,例如:InStr(TechnicPosition, .Body, vbCrLf)

But I can't get the last char (first "carriage return" from TechnicAction). I tried many things like : InStr(TechnicPosition, .Body, vbCrLf)

我的问题:如何得到一个从一个词开始的句子到回车"(在开始词之后的第一个)?

My question : how to get a sentence that begin from a word to a "carriage return" (the first that comes after the beginning word) ?

推荐答案

邮件正文中的回车通常是vbNewline

我通常是这样做的

Sub Sample()
    Dim sBody As String
    Dim MyAr
    Dim i As Long

    '
    '~~> Rest of your code
    '

    sBody = oMail.Body

    '~~> For testing purpose
    'sBody = "Hello," & vbNewLine & vbNewLine
    'sBody = sBody & "Please note we did ... at 16h15" & vbNewLine & vbNewLine
    'sBody = sBody & "Actions done: Rebuilding etc" & vbNewLine & vbNewLine
    'sBody = sBody & "Sincerely"

    '~~> Split the email body on vbnewline and store it in array
    MyAr = Split(sBody, vbNewLine)

    '~~> Loop through array
    For i = LBound(MyAr) To UBound(MyAr)
        '~~> Check if the line has "Actions done:"
        If InStr(1, MyAr(i), "Actions done:") Then
            '~~> This would give you "Rebuilding etc"
            '~~> Split the line on "Actions done:"
            '~~> You will get an array. Ar(0) will have "Actions done:"
            '~~> And Ar(1) will have what you are looking for so we use
            '~~> Split()(1) directly to access that item
            MsgBox Split(MyAr(i), "Actions done:")(1)
            Exit For
        End If
    Next i
End Sub

编辑

另一个方式

这篇关于查找“回车"在邮件正文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆