我有一些代碼,我能夠在我的Lotus Notes收件箱中輸入我收到的電子郵件的主題和一個電子郵件地址。像這樣:
Forward_Email "Subject text*"/span>, "[email protected]"/span>
然后代碼在我的收件箱中尋找Subject text,如果它找到一個與主題相匹配的電子郵件(在這種情況下,如果它找到一個主題為Subject text的電子郵件),那么它將轉發該郵件到指定的電子郵件地址。
然而問題是,當主題行包含字符#(哈希值)時,代碼不再能夠在收件箱中找到該主題行,并將vbCrLf & findSubjectLike & vbCrLf & "not found in Inbox" MsgBox作為回應。
如何讓它識別帶有#(散列)的主題行?
Public Sub Forward_Email(findSubjectLike As String, forwardToEmailAddresses As String)
Dim NSession As Object
Dim NMailDb As Object
Dim NViewObj As Variant
Dim NInboxView As Object
Dim NDocument As Object
Dim NUIWorkspace As Object
Dim NUIDocument As Object
Dim NFwdUIDocument As Object
Set NSession = CreateObject("Notes.NotesSession"/span>)
Set NUIWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set NMailDb = NSession.CurrentDatabase
For Each NViewObj In NMailDb. Views
If NViewObj.IsFolder And NViewObj.Name = "($Inbox)" Then
Set NInboxView = NViewObj
退出 為
End If
下一步 下一步
Set NDocument = Find_Document(NInboxView, findSubjectLike)
If Not NDocument Is Nothing Then
Set NUIDocument = NUIWorkspace.EditDocument(False, NDocument)
NUIDocument.Forward
Set NFwdUIDocument = NUIWorkspace.CurrentDocument
NFwdUIDocument.GoToField "To"
NFwdUIDocument.InsertText forwardToEmailAddresses
NFwdUIDocument.GoToField "Body""此郵件被轉發于" & Now
NFwdUIDocument.InsertText vbLf
NFwdUIDocument.Send
NFwdUIDocument.Close
DO
Set NUIDocument = NUIWorkspace.CurrentDocument
睡眠100。
睡眠
Loop While NUIDocument Is Nothing
NUIDocument.Close
Else[/span
MsgBox vbCrLf & findSubjectLike & vbCrLf & "未在收件箱中找到"。
結束 If
Set NUIDocument = Nothing
Set NFwdUIDocument = Nothing
Set NDocument = Nothing
Set NMailDb = Nothing[/span]。
Set NUIWorkspace = Nothing Nothing
Set NSession = Nothing Nothing
End Sub
Private Function Find_Document(NView As Object, findSubjectLike As String) As Object
Dim NThisDoc As Object
Dim thisSubject As String
Set Find_Document = Nothing
Set NThisDoc = NView.GetFirstDocument
While Not NThisDoc Is Nothing And Find_Document Is Nothing
thisSubject = NThisDoc.GetItemValue("Subject") (0)
If LCase(thisSubject) Like LCase(findSubjectLike) Then Set Find_Document=NThisDoc
Set NThisDoc = NView.GetNextDocument(NThisDoc)
補上
End Function[/span
如果有任何幫助,我們將不勝感激。
uj5u.com熱心網友回復:
這個問題是
If LCase(thisSubject) Like LCase(findSubjectLike) Then>
Like運算子接受模式匹配,#是通配符,代表任何單一數字(0-9)。
所以在If "#Subject text" Like "#Subject text" Then中,它尋找一個數字而不是#。所以你需要在findSubjectLike中用[#]替換#,這樣它就能得到[charlist] charlist中的任何一個字符。
LCase(Replace$(findSubjectLike, "#"/span>, "[#]"/span>)
注意,你可能還會遇到?和*以及[和]字符在主題中的問題,因為它們是Like運算子的特殊字符。
如果你沒有使用Like運算子的模式匹配...
...并試圖找到精確的匹配,那么你可以直接從Like切換到=
If LCase(thisSubject) = LCase(findSubjectLike) Then
...并嘗試找出findSubjectLike是否是thisSubject的一部分,那么你可以使用InStr函式
If InStr(thisSubject, findSubjectLike) > 0 Then
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/313423.html
標籤:
