I am using VBA to format all outbound email messages in a certain way before sending. For example, I want to remove the first column from all tables which are embedded in the email. I use the following code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim wd As Word.Document
Set wd = ActiveInspector.WordEditor
Dim tb As Word.Table
For Each tb In wd.Tables
tb.Columns(1).Delete
Next tb
End Sub
The above code works perfectly. However, the problem is that I only want to format my email text. Often, I will be responding to or forwarding someone else's email, which means that the text of the previous email will be in the same Inspector window. I don't want to format the text/images/etc. of the previous emails in the thread. How can this be achieved?
I know that each email within a thread--although they're all in the same window--is an individual unit. I know this because when reading an email which is part of a thread, as you move the mouse, you will see
on the right side of the screen, indicating where the next part of the thread is. When composing a new email (reply or forward) which is part of the thread, the above buttons are not shown, but you will still see a blue horizontal line separating the different parts of the thread from each other.
I was thinking that maybe I can search for the first occurrence of the line in the email, and only apply the formatting up until that point. However, it appears that the line isn't really text or any regular formatting which is searchable in the normal sense. In fact, if you copy the email text (before sending), and then paste into Word, the line disappears.
Any suggestions? Thanks!
Update
My question has nothing to do with the "conversation view" found in versions 2010 and later. Outlook 2010 allows you to view the other emails in the thread in one group. What I want, however, is to be able to loop through (via code) the emails in the thread within the same email. So, if there was an email "a", and then a reply, "b", and then another reply, "c", c will also contain b beneath it, and then a beneath that, all within the same email. In pseudo-code, I would want the following:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim wd As Word.Document
Dim smail as SubEmail
Dim tb As Word.Table
Set wd = ActiveInspector.WordEditor
For Each smail in wd
For Each tb In wd.Tables
tb.Columns(1).Delete
Next tb
Exit For
Next smail
End Sub
Update
I found a similar feature in Exchange Web Services, called UniqueBody. See here. That's exactly what I'm looking for, just not with Exchange.
Why not just look for "From:" chr(13) "Sent:" ? Outlook is going to put those tags in any email regardless of where it came from.
Assume that the entire body of emails a, b, c in your example above are in sBody:
Sub GetFirstThread()
Dim olItem As Outlook.MailItem
Dim sText As String
Set olItem = ActiveExplorer.Selection.Item(1)
sBody = olItem.Body
i=1
While i < Len(sBody)
If Asc(Mid(sBody, i, 1)) = 13 Then 'Look for From:
If Mid(sBody, i + 1, 5) = "From:" Then
'we found the start of email b
nPosEb = i
End If
End If
i=i+1
Wend
'...do something with nPosEb
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With