我在Outlook(2003)中使用VBA通过Outlook规则解析消息数据到一个CSV文件。我如何拿下面的例子并将“客户日志更新:”下的文本存储到字符串变量中?VBA查找substr与正则表达式
[Header Data]
Description: Problem: A2 - MI ERROR - R8036
Customer Log Update:
I'm having trouble with order #458362. I keep getting Error R8036, can you please assist?
Thanks!
View problem at http://...
[Footer Data]
期望的结果将被存储到字符串变量(注意,结果可能包含换行符):
I'm having trouble with order #458362. I keep getting Error R8036, can you please assist?
Thanks!
谢谢!
编辑:根据要求,这是我到目前为止。请注意,我没有试图编写与我的问题有关的任何内容。完全卡住了。
Function RegFind(RegInput, RegPattern)
Dim regEx As New VBScript_RegExp_55.RegExp
Dim matches, s
regEx.Pattern = RegPattern
regEx.IgnoreCase = True
regEx.Global = False
s = ""
If regEx.Test(RegInput) Then
Set matches = regEx.Execute(RegInput)
For Each Match In matches
s = Match.Value
Next
RegFind = s
Else
RegFind = ""
End If
End Function
Sub CustomMailMessageRule(Item As Outlook.MailItem)
MsgBox "Mail message arrived: " & Item.Subject
Const FileWrite = file.csv `file destination
Dim FF1 As Integer
Dim subj As String
Dim bod As String
On Error GoTo erh
subj = Item.Subject
'this gets a 15 digit number from the subject line
subj = RegFind(subj, "\d{15}")
bod = Item.Body
'following line helps formatting, lots of double newlines in my source data
bod = Replace(bod, vbCrLf & vbCrLf, vbCrLf)
'WRITE FILE
FF1 = FreeFile
Open FileWrite For Append As #FF1
Print #FF1, subj & "," & bod
Close #FF1
Exit Sub
erh:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
正则表达式中提取VBA?你目前写了什么代码? – 2012-02-09 20:29:13
我用正则表达式模式搜索很好,但遇到了这个更复杂的例子。答案可能不包括正则表达式,我不知道。 – 2012-02-09 20:37:27
请向我们展示您迄今为止编写的代码。 – 2012-02-09 20:41:25