VBscript to pull the first 3 lines out of Outlook email messages

  • Thread starter Thread starter scriptnewbie
  • Start date Start date
S

scriptnewbie

I am a script newbie here. and I was wondering if any experts out there
would help me with a script to pull the first 3 lines of all outlook
email messages out of a folder and paste them to a text file. Say you
have a folder with AutoPreview showing only the first 3 lines of the
messages and you want to just pull those preview lines out. is it
possible to just pull these first 3 lines and paste them all to a text
file? Any help would much be appreciated. Thanks
 
Am 16 Feb 2006 11:32:59 -0800 schrieb scriptnewbie:

This isn´t VBScript, but VBA. Maybe it helps despite of:

Public Sub CoolCode()
Dim obj as Object
Dim oMail as Outlook.MailItem
Dim oFld as Outlook.Mapifolder
Dim lLen as Long
Const FILE_NAME as String="c:\test.txt"

Set oFld=Application.Session.PickFolder
If Not oFld is Nothing Then
For Each obj in oFld.Items
If TypeOf obj is Outlook.MailItem Then
Set oMail=obj
lLen=GetPos(oMail.Body)
If lLen=0 Then lLen=Len(oMail.Body)
WriteFile FILE_NAME, Left$(oMail.Body, lLen), True
Endif
Next
Endif
End Sub

Private Sub WriteFile(sPath As String, _
sText As String, _
Optional ByVal bAppend As Boolean _
)
On Error GoTo AUSGANG
Dim lFileNr As Long

lFileNr = FreeFile
Select Case bAppend
Case False
Open sPath For Output As #lFileNr
Case Else
Open sPath For Append As #lFileNr
End If
Print #lFileNr, sText;

AUSGANG:
If lFileNr Then Close #lFileNr
If Err.Number Then Err.Raise &H800A0000 Or Err.Number, _
Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Sub

Private Function GetPos(sBody as String) as Long
Dim i as Long
Dim pos as Long

pos=1
For i=1 To 3
pos=Instr(pos, sBody, vbCRLF)
If pos=0 Then
Exit For
Else
pos=pos+2
Endif
Next
GetPos=pos
End Function
 
Thanks Michael for your response!. I saved this script as VBs extension
and tried to run it. It could not go past line 2. It gave me an error
message "Expected end of statement" at line 2 character 11. Any idea
how to fix it? thanks
 
Am 17 Feb 2006 08:28:39 -0800 schrieb scriptnewbie:

The almost only thing I know about VBS is that it doesn´t supports a type
declaration for variables.
 
Back
Top