![]() |
| 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. |
|
|||||||
| Tags: code, extract, line, subject |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | |
|
|
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 |