PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Extract several lines of email messages starting from the end
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Extract several lines of email messages starting from the end
![]() |
Extract several lines of email messages starting from the end |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi everyone,
I was hoping that someone would give me an idea how to accomplish this. I would like to pull out say the last 5 lines of all messages in my Inbox folder and write them all to a text file. I was thinking about creating a function and set a Position variable to the end of message, but no success. I can get the first couple lines with the below function. But how can I write my code to get the last 5 lines of the messages. Thnx in advance for your help. Private Function GetPosition(sBody As String) As Long Dim p As Long Dim position As Long position = 1 For p = 1 To 5 position = InStr(position, sBody, vbCrLf) position = position + 1 Next GetPosition = position End Function |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Am 16 Mar 2006 11:57:49 -0800 schrieb scriptnewbie:
You could search with InStrRev for vbCRLF backwards. For 5 lines you then need to look for 6 vbCRLF (or 5 if the first of the 5 lines is also the first line at all). -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- > Hi everyone, > > I was hoping that someone would give me an idea how to accomplish this. > I would like to pull out say the last 5 lines of all messages in my > Inbox folder and write them all to a text file. I was thinking about > creating a function and set a Position variable to the end of message, > but no success. I can get the first couple lines with the below > function. But how can I write my code to get the last 5 lines of the > messages. Thnx in advance for your help. > > Private Function GetPosition(sBody As String) As Long > Dim p As Long > Dim position As Long > position = 1 > For p = 1 To 5 > position = InStr(position, sBody, vbCrLf) > position = position + 1 > Next > GetPosition = position > End Function |
|
|
|
#3 |
|
Guest
Posts: n/a
|
You can also use this :
Private Function GetLines(ByVal text As String) As String() Dim tb As New System.Windows.Forms.TextBox tb.Multiline = True tb.Text = text Return tb.Lines End Function (Why do all the work by hand?) ![]() Klaus |
|
|
|
#4 |
|
Guest
Posts: n/a
|
That, of course, assumes you're using VB.NET, which scriptnewbie did not say he was using.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Klaus" <k.burger@chello.at> wrote in message news:1142592307.542485.257000@v46g2000cwv.googlegroups.com... > You can also use this : > > Private Function GetLines(ByVal text As String) As String() > Dim tb As New System.Windows.Forms.TextBox > tb.Multiline = True > tb.Text = text > Return tb.Lines > End Function > > (Why do all the work by hand?) ![]() > > Klaus > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks everyone for quick response! I am writing this script as a
macro for Outlook 2003. I am not using VB.Net at all. Michael, could you elaborate your suggestion more? I am looking to get the last 5 lines of the all email messages. |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Am 17 Mar 2006 09:23:59 -0800 schrieb scriptnewbie:
Instr searches forwards, InstrRev does it backwards. The rest you do know already, just look for vbCRLF. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- > Thanks everyone for quick response! I am writing this script as a > macro for Outlook 2003. I am not using VB.Net at all. > Michael, could you elaborate your suggestion more? I am looking to get > the last 5 lines of the all email messages. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


