A
acampbell012
I found this code from an '02 posting which is supposed to extract the
subject line from a designated Outlook folder. The code crashes on the
line "AscName = Asc(CharName)"; Error 5, "Invalid procedure call or
argument".
I am using Outlook 2003 and would like to utilize this code to export
the subject line.
Thanks.
Alan
Sub ProcessTheInbox()
Dim fName As String
Dim i As Long
Dim oApp As Outlook.Application
Dim oFoldMail As Object
Dim oItem As Outlook.MailItem
Dim oNameSp As Outlook.NameSpace
Dim x As Long
Dim strSubject As String
Dim sName As String
Dim z As Long
'Open or attach to Outlook
Set oApp = New Outlook.Application
Set oNameSp = oApp.GetNamespace("MAPI")
'Attach to the appropriate folders
Set oFoldMail = oNameSp.GetDefaultFolder(6) '6=Inbox
'Process mail items
z = 0
x = oFoldMail.Items.Count
MsgBox "The number of emails in " & CStr(oFoldMail) & " is " &
CStr(x)
Open "c:\output.txt" For Output As #1
For i = x To 1 Step -1
Set oItem = oFoldMail.Items.Item(i)
strSubject = oItem.Subject
If Left(strSubject, 4) = "test" Or Left(strSubject, 4) = "TEST"
Then
z = z + 1
sName = TrimUserName(strSubject)
MsgBox "The name returned is " & sName
Write #1, sName
End If
Next i
MsgBox "The number of emails processed is " & CStr(z)
Close #1
Set oApp = Nothing
Set oFoldMail = Nothing
Set oItem = Nothing
Set oNameSp = Nothing
End Sub
Function TrimUserName(ByVal Subjectline)
Dim AscName
Dim RightName
Dim i As Integer
Dim iFoundPos As Integer
Dim iLen As Integer
iLen = Len(Subjectline)
MsgBox Subjectline & " = Length of Subject field is " & Str(iLen)
AscName = 0
iFoundPos = 0
For i = 0 To iLen
Do While Not (AscName = 35) '# delimiter
iFoundPos = iFoundPos + 1
CharName = Mid(UCase(Subjectline), i + 1, 1) 'trawl through
the
Subject
AscName = Asc(CharName)
i = i + 1
Loop
Next
RightName = Right(Subjectline, (iLen - iFoundPos))
TrimUserName = RightName
End Function
subject line from a designated Outlook folder. The code crashes on the
line "AscName = Asc(CharName)"; Error 5, "Invalid procedure call or
argument".
I am using Outlook 2003 and would like to utilize this code to export
the subject line.
Thanks.
Alan
Sub ProcessTheInbox()
Dim fName As String
Dim i As Long
Dim oApp As Outlook.Application
Dim oFoldMail As Object
Dim oItem As Outlook.MailItem
Dim oNameSp As Outlook.NameSpace
Dim x As Long
Dim strSubject As String
Dim sName As String
Dim z As Long
'Open or attach to Outlook
Set oApp = New Outlook.Application
Set oNameSp = oApp.GetNamespace("MAPI")
'Attach to the appropriate folders
Set oFoldMail = oNameSp.GetDefaultFolder(6) '6=Inbox
'Process mail items
z = 0
x = oFoldMail.Items.Count
MsgBox "The number of emails in " & CStr(oFoldMail) & " is " &
CStr(x)
Open "c:\output.txt" For Output As #1
For i = x To 1 Step -1
Set oItem = oFoldMail.Items.Item(i)
strSubject = oItem.Subject
If Left(strSubject, 4) = "test" Or Left(strSubject, 4) = "TEST"
Then
z = z + 1
sName = TrimUserName(strSubject)
MsgBox "The name returned is " & sName
Write #1, sName
End If
Next i
MsgBox "The number of emails processed is " & CStr(z)
Close #1
Set oApp = Nothing
Set oFoldMail = Nothing
Set oItem = Nothing
Set oNameSp = Nothing
End Sub
Function TrimUserName(ByVal Subjectline)
Dim AscName
Dim RightName
Dim i As Integer
Dim iFoundPos As Integer
Dim iLen As Integer
iLen = Len(Subjectline)
MsgBox Subjectline & " = Length of Subject field is " & Str(iLen)
AscName = 0
iFoundPos = 0
For i = 0 To iLen
Do While Not (AscName = 35) '# delimiter
iFoundPos = iFoundPos + 1
CharName = Mid(UCase(Subjectline), i + 1, 1) 'trawl through
the
Subject
AscName = Asc(CharName)
i = i + 1
Loop
Next
RightName = Right(Subjectline, (iLen - iFoundPos))
TrimUserName = RightName
End Function