gpt4 book ai didi

vba - 在mail.body中查找 "carriage return"

转载 作者:行者123 更新时间:2023-12-03 02:42:14 25 4
gpt4 key购买 nike

我有这样的邮件:

Hello,

Please note we did ... at 16h15

Actions done: Rebuilding etc

sincerely

Mr.

每封邮件中的操作都会发生变化,我想要的是将操作插入到我的 Excel 中。问题是我不知道如何获得“回车符”(我不知道这是否是正确的名称,这就是翻译给我的)。我在互联网上找到的是 vbLfChr(10) 是“回车符”。我尝试的是找到开始:

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

但我无法获取最后一个字符(TechnicAction 中的第一个“回车符”)。我尝试了很多东西,例如: InStr(TechnicPosition, .Body, vbCrLf)

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

最佳答案

电子邮件正文中的回车通常为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

编辑

ANOTHER WAY

关于vba - 在mail.body中查找 "carriage return",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com