我在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