如何让我的各个模块协同工作?

How do I get my individual modules to work together?

我们在 A 列和 B 列中手动输入信息,工作表用于比较主题行。

我们收到进入收件箱的带有特定主题的电子邮件,这些主题与 B 列中的数据相匹配。这些电子邮件还有为 A 列中的电子邮件地址指定的附件。通常我们所做的是检查主题电子邮件,找到包含与 B 列中相同的主题信息的行,然后将该电子邮件转发到同一行的 A 列中的电子邮件。


Dim v As Object
Dim vn As Object
Dim e As Object
Dim doc As Object
Dim rtitem As Variant
Dim nit As Object

View = "$All"

Set NSession = CreateObject("Notes.NotesSession")
Set NMailDb = NSession.GetDatabase("", "")
If Not NMailDb.IsOpen Then
        NMailDb.OPENMAIL
    End If
    
Set v = NMailDb.GetView(View)
Set vn = v.CreateViewNav()


Set e = vn.GetFirstDocument()


Do While Not (e Is Nothing)

     Set doc = e.Document
     Lines = doc.GetItemValue("subject")
     Range("C1").Resize(UBound(Lines) + 1, 1).Value = Application.WorksheetFunction.Transpose(Lines)
     Set e = vn.GetNextDocument(e)

Loop
End Sub

此代码查看我的 Lotus Notes 收件箱(我需要打开收件箱才能工作,但这没关系)它获取收件箱中每封电子邮件的主题行并将其输入到 C1 中。然后它对下一封电子邮件再次执行此操作并覆盖 C1,此循环直​​到它每次遍历所有电子邮件覆盖 C1。

Public Sub SubstringCheck()
Dim i As Long, icount As Integer
Dim lastrow As Long
Dim MainString As String
Dim SubString As Variant

lastrow = ActiveSheet.Range("A30000").End(xlUp).Row

For i = 1 To lastrow

MainString = Range("C1")
SubString = Range("B" & i)


If InStr(1, LCase(MainString), LCase(SubString), vbTextCompare) <> 0 Then
Forward_Email MainString, Range("A" & i)

icount = icount + 1
ElseIf InStr(LCase(MainString), LCase(SubString)) = 0 Then

End If
Next i
End Sub

此代码获取 C1 中的任何内容,并将其与 B 列中的每个条目进行比较。当它发现 C1 与 B 列中的任何值匹配时,它然后 运行s Forward_Email 函数返回到 C1 中主题行的 Lotus Notes,按主题行查找电子邮件并使用匹配行的电子邮件地址形式转发它。

我的问题是,我想把我的代码 (Substring_Check) 和 运行 放在用主题行填充 C1 的代码中。我想在下一个循环写入 C1 之前让它 运行,这样 Substring_Check 可以用 B 列中的信息检查 C1 中的信息,如果有匹配,它将转发电子邮件,如果没有然后循环可以覆盖 C1 中的信息并重复。实现合并的最佳方式是什么?

理查德在他的评论中写道,答案似乎微不足道,但我还是会尝试:

您根本不需要在代码中编写 C1。在您的循环中,只需添加对带有参数的子字符串查找函数的调用:

Dim subject as String
Do While Not (e Is Nothing)

     Set doc = e.Document
     subject = doc.GetItemValue("subject")(0)
     SubstringCheck subject
     Set e = vn.GetNextDocument(e)

Loop

Subject 通常只包含一个值,我们不需要数组来进行字符串比较,我们只使用第一个值并将其作为参数传递给函数。

Public Sub SubstringCheck( MainString as String )
    Dim i As Long, icount As Integer
    Dim lastrow As Long
    Dim SubString As Variant
    
    lastrow = ActiveSheet.Range("A30000").End(xlUp).Row
    
    For i = 1 To lastrow
        
        SubString = Range("B" & i)
        
        If InStr(1, LCase(MainString), LCase(SubString), vbTextCompare) <> 0 Then
            Forward_Email MainString, Range("A" & i)
            icount = icount + 1
        ElseIf InStr(LCase(MainString), LCase(SubString)) = 0 Then
        
        End If
    Next i
End Sub

这还远未达到最佳状态,但可以回答您的问题...