1
I am writing the following vbscript program to read an .eml file and extract the email ID of the sender. Though it runs successfully without any error, it does not show the msgbox with the email ID. Please guide me how to resolve this issue.
This Code works fine with VBA.
Sub reademl()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, MyFile, FileName, emlid, strLine
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file for output.
FileName = "C:\Documents\VBScript\test-sample-message.eml"
Set MyFile = fso.OpenTextFile(FileName, ForReading, True, TristateTrue)
Do While MyFile.AtEndOfStream <> True
strLine = MyFile.ReadLine
If(InStr(strLine,"To:")<>0) Then
emlid=Mid(strLine,InStr(strLine,":")+2,Len(strLine)-InStr(strLine,":")-1)
Exit Do
End If
Loop
MsgBox(emlid)
MyFile.Close
End Sub
Alternatively, move the content of the sub to "main()" and delete the Sub (There is no requirement for main() in vbscript, AFAIK, but hopefully the point of the comment is clear) – Yorik – 2017-02-28T18:58:17.533