Foward email to Trello without FW in subject and parce the text

Status
Not open for further replies.

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'd try
.Pattern = "(follows[:](.*))"
for the second pattern - since you want everything after that. If it adds a line feed at the top, try \n or \r before (.*).
 
Outlook version
Email Account
IMAP
since you want everything after the cc number, try this - it might be case sensitive so use the proper case for the cc (i forget :))

.Pattern = "cc-(\d*)\s*(.*)"

you might need to use
.MultiLine = True
with case 2. put it after the .global = false line.
like this:

Sub ForwardProjectcard()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1
Select Case i
Case 1
.Pattern = "cc-(\d*)\s*(.*)"
.Global = False
Case 2
.Global = False
.Pattern = "(request follows(.*)[:]\s*(.*)).\s*\n"
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

'Assigns Category to Mailitem
olMail.Categories = "Projects"
olMail.Save

Next i

Set myForward = olMail.Forward
myForward.To = "judithharris3+rkwzzut2ssv2nuugsfdj@boards.trello.com"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Display



Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing


End Sub
 
Outlook version
Email Account
IMAP
HOUSTON WE HAVE A SUBJECT! WHOO HOOO....
Still no body yet but brought up the window,
put in the to: and put in the subject (without the FW like I needed)
 
Outlook version
Email Account
IMAP
Ok I changed it to this and got one line in the subject

Case 2
.Global = False
.Pattern = "request follows[:](\d*)\s*(.*)"
.MultiLine = True
End Select
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Test it with
. Pattern = "(request follows(.*))"

Start small and work up...
 
Outlook version
Email Account
IMAP
Ok this one gave me nothing...
. Pattern = "(request follows(.*))"

This one gave me one line only..
Case 2
.Global = False
.Pattern = "request follows[:](\d*)\s*(.*)"
.MultiLine = True
End Select
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Try .global = true
You'll need to do strfollows = strfollows & vbcrlf & strresult(2) to build the string.
 
Outlook version
Email Account
IMAP
Ok so I've tried all the patterns I could find, the ones you suggested and ones that I've tried to put together but this is the closest I've gotten This will deliver the last word on every line that has a colon and I have no idea how that happened.

Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1

Select Case i
Case 1
.Pattern = "CC-(\d*)\s*(.*)"
.Global = False
Case 2
.Pattern = "((\w*)\s*(\w*))\n"
.Global = True
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strFollows & vbCrLf & strResult(2)

Next
End If

Next i
 
Outlook version
Email Account
IMAP
well I tried this one:
.Pattern = "(\d*)\s*(.*)"

and it delivers the entire body of the text... If I add follows[:] then I get nothing.
Maybe it would be easier to remove the first part instead of capture the last part...
Any ideas would be greatly appreciated. I'm extremely frustrated at this point.
Also, how do I make this work for all emails in a folder instead of just one.
 
Outlook version
Email Account
IMAP
If I add searching for the ! then I only get ONE LINE
Without it I get the entire email body...

Case 2
.Pattern = "[!](\w*)\s*(.*)"
.Global = True
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strFollows & strResult(2)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
do you want the entire block of text after follows or just the data side, without the labels? using (.*) should get each line in it's entirety.

This: Pattern = "((\w*)\s*(\w*))\n" looks for alpha numeric ending with a line break.

This should get everything after follows (with global = true)
. Pattern = "(request follows[:](.*))"

Edited to add the [:]
 
Outlook version
Email Account
IMAP
do you want the entire block of text after follows or just the data side, without the labels? using (.*) should get each line in it's entirety.

This: Pattern = "((\w*)\s*(\w*))\n" looks for alpha numeric ending with a line break.

This should get everything after follows (with global = true)
. Pattern = "(request follows[:](.*))"

Edited to add the [:]

This is just so weird because it should work but it doesn't! I must have something else wrong and I'm over looking it.
I even removed the move to specific folder and assign category just to make sure it wasn't messing it up.

Here is latest code. Maybe you can see something in the wrong place or typo??? I'm scratching my head on this one.
Should be quite simple... and yes everything after the follows:


Sub CreateProjectcards()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1

Select Case i
Case 1
.Pattern = "CC-(\d*)\s*(.*)"
.Global = False
Case 2
.Pattern = "(follows[:](.*))"
.Global = True
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strFollows & strResult(2)

Next
End If

Next i

Set myForward = olMail.Forward
myForward.To = "userid@boards.trello.com"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Display

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
What exactly happens?

Might need to go back to
strFollows = strResult(2)

and add something like
strBody = strBody & strFollows[DOUBLEPOST=1412364908][/DOUBLEPOST]Also, look in the immediate window (ctrl+6) - are the lines 'printing' ?
 
Outlook version
Email Account
IMAP
What exactly happens?

Might need to go back to
strFollows = strResult(2)

and add something like
strBody = strBody & strFollows[DOUBLEPOST=1412364908][/DOUBLEPOST]Also, look in the immediate window (ctrl+6) - are the lines 'printing' ?


This one opens up an email.. puts in the correct to address and subject but has no body
upload_2014-10-3_15-47-39.png
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This won't work: .Pattern = "(follows[:](.*))" bad thinking on my part - .Pattern = "((.*))" would get the entire message.

If you use global = True, it repeats the pattern - but the pattern only exists once. We need it to pick up everything. I don't know where my logic was yesterday (well, I do - i was working on a project with a deadline and i wasn't testing it with anything close to the same message format. Today I have a message with a colon in it, near the top.)

It might be easier to delete lines - i don't know. Or, it's just a matter of finding the right regex. I'm not a regex expert by any means and could be doing something wrong.
 
Outlook version
Email Account
IMAP
Ok here is what I finally came up with. It might be ugly but it works... :)
Two final questions. There is a space in the subject line before the subject and i'm not sure why and also you said earlier that this is a one message script. How do I change it to apply to all emails in a folder?

Sub trellofwd(Item As Outlook.MailItem)
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1

Select Case i
Case 1
.Pattern = "(CC-\d*\s*)(.*)"
.Global = False
Case 2
.Pattern = "(follows[:]\s*\n)+(\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*))"
.Global = True
.MultiLine = True
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

Next i

Set myForward = olMail.forward
myForward.To = "judithharris3+rkwzzut2ssv2nuugsfdj@boards.trello.com"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Send

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing

End Sub
 
Outlook version
Email Account
IMAP
Two final questions. There is a space in the subject line before the subject and i'm not sure why and also you said earlier that this is a one message script. How do I change it to apply to all emails in a folder?
 
Outlook version
Email Account
IMAP
My script seems to be running for each mail in the folder but it keeps sending the same information for the same email for each number of emails in the box...
Not sure what I need to change in my code?
I think it may have to do with this line but it errors when I remove it:
Set olMail = Application.ActiveExplorer().Selection(1)
 

Forum Admin

Senior Member
Hmm. It looks like i missed a lot of mail in October (went on vacation and missed it :()

The dim and set mail lines need to be deleted.

Problem #1 - you need to change olMail to Item (or change Item to olMail)
This line tells it to refer to the message object as Item:
Sub trellofwd(Item As Outlook.MailItem)
But you refer to it as olmail in the macro:
If Reg1.Test(olMail.Body) Then
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Appending text to the subject line of a Reply, Foward or new Email Outlook VBA and Custom Forms 2
Diane Poremsky Foward a Message and CC the Original Recipients Using Outlook 0
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 3
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
P default font when sending email from browser Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
B IMAP server rejects sent email - cannot deliver messages Using Outlook 2
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Email notifications changed with Outlook 2021 Using Outlook 8
glnz How to retrieve or redo Verizon.net email password without affecting Outlook connection? Using Outlook 1
Z Copy specific email body text Outlook VBA and Custom Forms 0
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
M Outlook 365 refuses to send email Using Outlook 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
K Closing external IMAP email... Outlook 2013 Using Outlook 0
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
C Email bomb processing Outlook VBA and Custom Forms 1
O What would be the recommended way to change an email address (family member)? Using Outlook 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
D Wrong email address in Outlook 2003 "From" tab in new outgoing emails Using Outlook 4
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
G Place jpg in body of email Outlook VBA and Custom Forms 1
F Wishlist Outlook suddenly began synchronizing deleted items every time I delete a single email. Using Outlook 2
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 12
F Email being marked as Spam by Gmail and not being visible in Outlook Using Outlook 5
G Email time stamp Using Outlook 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
K Multiple Rules on Single Email Using Outlook 2
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
D Outlook launch email showing new unread email in reading pane Using Outlook 11

Similar threads

Top