By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

return multiple lines

P: 2
I have a large body of text and am trying to extract parts of that into a field in my form. i am using the following code:

Expand|Select|Wrap|Line Numbers
  1. If InStr(1, abody(j), "Extent of Work:", 1) Then
  2. strExtWork = Mid(abody(j), InStr(abody(j), "Extent of Work:") + 16)
this works well in returning one line, but sometimes the extent of work that i am trying to extract is multiple lines and i have kind of hit a wall... any ideas?

Thank you.
4 Weeks Ago #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,429
Not much really, without knowing what problem(s) you're experiencing.
4 Weeks Ago #2

P: 2
I am importing the body of emails and am taking specific strings from the email and placing them in fields on a form. For text that i am capturing that is only one row it is not a problem. the problem is if the data i need to import is on multiple rows. i have tried this code:

Expand|Select|Wrap|Line Numbers
  1. Dim rowOffset As Long
  2.  
  3. If InStr(1, abody(j), "Extent of Work:", 1) Then
  4.    strExtWork = Mid(abody(j), InStr(abody(j), "Extent of Work:") + 16)
  5.  
  6.  
  7.     rowOffset = 1  ' reinit
  8.     While Left(abody(j + rowOffset), 8) <> "Remarks:" ' check if this is Remarks:
  9.         strExtWork = strExtWork & abody(j + rowOffset)
  10.         rowOffset = rowOffset + 1
  11.         Me.ExtentofWork = Trim(strExtWork)
  12.     Wend
  13.                     End If
As the end point will always be the word "Remarks:". This works for capturing multiple rows of text but if there is just a single row it does not capture that.

To summarize, I am trying to capture all text between the words "Extent of Work:" and "Remarks"

The problem is I can either capture one row, or multiple, with the codes provided, but not but situations.
4 Weeks Ago #3

ADezii
Expert 5K+
P: 8,627
I loaded an E-Mail Item which I know has extensive Body Text into a String Variable after Trimming it and Replacing CrLfs with an Empty String. I then calculated my Positions and returned all Text between 'Extent of Work:' and 'Remarks:'. It appears to work quite well but not fully tested.
Expand|Select|Wrap|Line Numbers
  1. Dim strBody As String
  2. Dim strBody2 As String
  3. Dim intStart As Integer
  4. Dim oLook As Outlook.Application
  5. Dim oMailItems As Outlook.Items
  6. Dim msg As Outlook.MailItem
  7. Dim strFldInfo As String
  8. Dim intPos1 As Integer
  9. Dim intPos2 As Integer
  10. Const conSEARCH1 = "Extent of Work:"
  11. Const conSEARCH2 = "Remarks:"
  12.  
  13.  
  14. Set oLook = New Outlook.Application
  15. Set oMailItems = oLook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
  16.  
  17. For Each msg In oMailItems
  18.   If msg.Subject = "Test" Then
  19.     strBody = Replace(Trim(msg.Body), vbCrLf, "")
  20.       intPos1 = InStr(1, strBody, conSEARCH1) + Len(conSEARCH1)
  21.       intPos2 = InStr(1, strBody, "Remarks:")
  22.       strFldInfo = Mid$(strBody, intPos1, (intPos2 - intPos1) - 1)
  23.         Debug.Print strFldInfo
  24.   End If
  25. Next
  26.  
  27. Set oLook = Nothing
  28. Set msg = Nothing
  29. Set oMailItems = Nothing
4 Weeks Ago #4

twinnyfo
Expert Mod 2.5K+
P: 3,255
ADezii,

Great work, as usual! Simple. Elegant. Looks functional.
3 Weeks Ago #5

ADezii
Expert 5K+
P: 8,627
@twinnyfo
Thanks for your kind words.
3 Weeks Ago #6

Post your reply

Sign in to post your reply or Sign up for a free account.