A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , ,

Code to extract subject line





 
 
Thread Tools Display Modes
  #1  
Old August 24th 06, 07:45 PM posted to microsoft.public.outlook.program_vba
acampbell012@yahoo.com
external usenet poster
 
Posts: 2
Default Code to extract subject line

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

Ads
  #2  
Old August 25th 06, 06:04 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,164
Default Code to extract subject line

Am 24 Aug 2006 11:45:06 -0700 schrieb :

Please ensure that the CharName variable isnīt empty.

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


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".

  #3  
Old August 25th 06, 03:59 PM posted to microsoft.public.outlook.program_vba
acampbell012@yahoo.com
external usenet poster
 
Posts: 2
Default Code to extract subject line

It is not empty but, it is blank (i.e. "")

Just to test the results, I changed CharName = Mid(UCase(Subjectline),
i + 1, 1) to

CharName = Mid(UCase(Subjectline), i - 1, 1) and it shows empty.

I do some VBA programming in Excel but, Outlook is new to me. I am not
sure what this function is attempting to do within the sub in order to
diagnose why it crashes. I have tried several mods to the search
string, testing known subject line in my inbox and have had no success.
I read help on Asc function, but not sure what purpose it is serving in
this code/function.

Appreciate any additonal feedback you can provide.


Michael Bauer [MVP - Outlook] wrote:
Am 24 Aug 2006 11:45:06 -0700 schrieb :

Please ensure that the CharName variable isnīt empty.

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


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".


  #4  
Old August 25th 06, 06:54 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,164
Default Code to extract subject line

Am 25 Aug 2006 07:59:58 -0700 schrieb :

With "empty" I mean also blank. If the string is blank ("") then an error
occurs.

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


It is not empty but, it is blank (i.e. "")

Just to test the results, I changed CharName = Mid(UCase(Subjectline),
i + 1, 1) to

CharName = Mid(UCase(Subjectline), i - 1, 1) and it shows empty.

I do some VBA programming in Excel but, Outlook is new to me. I am not
sure what this function is attempting to do within the sub in order to
diagnose why it crashes. I have tried several mods to the search
string, testing known subject line in my inbox and have had no success.
I read help on Asc function, but not sure what purpose it is serving in
this code/function.

Appreciate any additonal feedback you can provide.


Michael Bauer [MVP - Outlook] wrote:
Am 24 Aug 2006 11:45:06 -0700 schrieb :

Please ensure that the CharName variable isnīt empty.

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


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".

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to extract subject line and "paste" in advanced search stef Outlook and VBA 2 August 20th 06 11:24 PM
Re-Post: macro to extract subject line and "paste" in advanced search stef Outlook and VBA 5 August 8th 06 11:02 PM
Re-Post: macro to extract subject line and "paste" in advanced search stef Add-ins for Outlook 0 August 7th 06 01:45 AM
macro to extract subject line and "paste" in advanced search stef Add-ins for Outlook 0 August 2nd 06 04:21 PM
Subject line Peter Outlook Express 1 May 21st 06 10:10 AM


All times are GMT +1. The time now is 08:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright Đ2004-2008 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
Finance - Credit Cards - Mortgage - Online Advertising - Mortgages