Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   VBscript to pull the first 3 lines out of Outlook email messages (http://www.outlookbanter.com/outlook-vba/7467-vbscript-pull-first-3-lines.html)

scriptnewbie February 16th 06 07:32 PM

VBscript to pull the first 3 lines out of Outlook email messages
 
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


Michael Bauer February 17th 06 07:02 AM

VBscript to pull the first 3 lines out of Outlook email messages
 
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

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


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


scriptnewbie February 17th 06 04:28 PM

VBscript to pull the first 3 lines out of Outlook email messages
 
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


Michael Bauer February 18th 06 09:48 AM

VBscript to pull the first 3 lines out of Outlook email messages
 
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.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


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



All times are GMT +1. The time now is 10:42 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com