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

Status
Not open for further replies.
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 (.*).
 
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
 
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)
 
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
 
Test it with
. Pattern = "(request follows(.*))"

Start small and work up...
 
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
 
Try .global = true
You'll need to do strfollows = strfollows & vbcrlf & strresult(2) to build the string.
 
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
 
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.
 
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)
 
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 [:]
 
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
 
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' ?
 
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
 
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.
 
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
 
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?
 
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)
 
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
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 3
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
S Email was migrated from GoDaddy to Microsoft exchange. We lost IMAP ability Exchange Server Administration 1
R Outlook 365 How to integrate a third-party app with Outlook to track email and sms? Using Outlook 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
Rupert Dragwater How to permanently remove an email address Using Outlook 9
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 4
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Shift Delete doesn't delete email from server Using Outlook 3
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
L Why are some email automatically going to "archive" Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 7
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 1
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 0

Similar threads

Back
Top