我正在尝试使用 InStr 在数组中查找值。但是,我得到了误报和误报。
即会有一个字符串匹配,即使字符串完全匹配,也不会报告匹配或不报告匹配。
它需要 Outlook。它将突出显示的电子邮件转换为放置在指定路径中的文本文件。然后,它通过将文本读入数组并搜索数组内容来搜索文本文件中的分隔符。但是,如前所述,即使子字符串在数组中,InStr 也会返回误报和误报。我尝试过二进制和文本比较方法以及各种比较字符串。
有任何想法吗?
注意: 1)在对 InStr 感到沮丧之后,我尝试使用 if then 语句将数组与分隔符字符串进行比较,这就是我的代码最后几行中显示的内容。2)我已将分隔符设置为“xxxxx”,您可以在 objfile.write 命令集之后的行中看到它。3)我尝试使用 instr 函数同时使用文本和二进制比较模式
3) 最终目标: a) 从 Outlook 中提取突出显示的电子邮件并合并到一个文本文件中。b) 根据电子邮件的文本对分隔的文本文件进行排序(如果分隔符之间的文本包含 y,则放入数组 y,如果 x...等) c) 按我指定的顺序将数组打印到电子邮件中(例如 x,y , z)
这是因为电子邮件每天到达的时间不同,但必须每天按相同的顺序组织最终的摘要电子邮件。
谢谢。
下面是我的代码:
Sub MergeTextFromSelectedEmailsIntoTextFile()
Dim objFS As New Scripting.FileSystemObject, objFile As Scripting.TextStream
Dim objItem As Object, strFile As String
Dim wrapArray() As String
If ActiveExplorer.Selection.Count = 0 Then Exit Sub
strFile = InputBox("Please enter the full path and file name for the merged text:" _
, "Enter File Name")
Set objFile = objFS.CreateTextFile(strFile, False)
If objFile Is Nothing Then
MsgBox "Error creating file '" & strFile & "'.", vbOKOnly + vbExclamation _
, "Invalid File"
Exit Sub
End If
For Each objItem In ActiveExplorer.Selection
objFile.Write vbCr
objFile.Write (vbCr & Chr(10) & Chr(13) & ("xxxxx") & Chr(13) & Chr(13) & vbCr & vbLf)
objFile.Write (vbCr & vbLf & objItem.Body)
objFile.Write (vbCr & vbLf & Chr(13))
Next
objFile.Close
'Define variables for writing to array
Dim i As Integer
Set objFile = objFS.OpenTextFile(strFile, ForReading)
'write file contents to array
Do Until objFile.AtEndOfStream
ReDim Preserve wrapArray(i)
wrapArray(i) = objFile.ReadLine
i = i + 1
Loop
Dim xxxxx As String
xxxxx = xxxxx
'check each array index for contents
'note i have tried
''if instr(0, wraparray(i), "xxxxx",0) then msgBox "FoundDelim at line " & i
For i = LBound(wrapArray()) To UBound(wrapArray())
If wrapArray(i) = "xxxxx" Then MsgBox "FoundDelim! at line " & i
Next i