travisdh
10-11-2012, 09:02 PM
Hi All,
I have a three part question, the first is that I am using the code below to look for CV, or CN in the subject, and where it detects it, it will extract the first eight characters (including the CV or CN) and create a folder in public folders with that code, the idea is that all emails both sent and received are put into that folder to keep a per project history going.
I am having a few issues though, the first is that when the code is run it creates a copy of the email and moves it, which is fine but there is always one spare email left in the outbox even after the email is sent. How can i go about moving this or deleting this spare email so there is one in the normal sent, and another in the public folder project folder.
The second question is, with the below the emails tend to be put into the project folder, but are marked as not sent. Is there any way i can have them be sent first, then moved so they are accurate in that they are marked as being sent?
The final question, which i hope is an easy one, is the structure of the code I am looking for is generally CV (or CN) then YY then MM then ID all in numbers, is there a way i can use a regex string to get the CVxxxxxx where xxxxxx are all numbers? this would be more accurate as at the moment if ever CV or CN is detected it will extract eight characters, however it would be nice to only work if CV or CNxxxxxx is detected, then only extract that to have better error handling.
Thanks!
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Subject As String
Dim openingParen As String
Dim closingParen As String
Dim enclosedValue As String
Dim profolder As Outlook.folder
Dim itm As Object
Set ObjCopy = Item.Copy
Subject = Item.Subject
If InStr(1, Item.Subject, "CV", vbTextCompare) > 0 Then
Prefix = "CV"
MoveEmail "CV", Subject
ElseIf InStr(1, Item.Subject, "CN", vbTextCompare) > 0 Then
Prefix = "CN"
MoveEmail "CN", Subject
Else
Cancel = False
End If
End Sub
Private Sub MoveEmail(Prefix As String, Subject As String)
openingParen = InStr(Subject, Prefix)
closingParen = InStr(Subject, "]")
enclosedValue = Mid(Subject, openingParen, 8)
TestGetFolder (enclosedValue)
Set folder = GetFolder("\\Public Folders\All Public Folders\Projects\" & enclosedValue)
ObjCopy.Move folder
End Sub
I have a three part question, the first is that I am using the code below to look for CV, or CN in the subject, and where it detects it, it will extract the first eight characters (including the CV or CN) and create a folder in public folders with that code, the idea is that all emails both sent and received are put into that folder to keep a per project history going.
I am having a few issues though, the first is that when the code is run it creates a copy of the email and moves it, which is fine but there is always one spare email left in the outbox even after the email is sent. How can i go about moving this or deleting this spare email so there is one in the normal sent, and another in the public folder project folder.
The second question is, with the below the emails tend to be put into the project folder, but are marked as not sent. Is there any way i can have them be sent first, then moved so they are accurate in that they are marked as being sent?
The final question, which i hope is an easy one, is the structure of the code I am looking for is generally CV (or CN) then YY then MM then ID all in numbers, is there a way i can use a regex string to get the CVxxxxxx where xxxxxx are all numbers? this would be more accurate as at the moment if ever CV or CN is detected it will extract eight characters, however it would be nice to only work if CV or CNxxxxxx is detected, then only extract that to have better error handling.
Thanks!
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Subject As String
Dim openingParen As String
Dim closingParen As String
Dim enclosedValue As String
Dim profolder As Outlook.folder
Dim itm As Object
Set ObjCopy = Item.Copy
Subject = Item.Subject
If InStr(1, Item.Subject, "CV", vbTextCompare) > 0 Then
Prefix = "CV"
MoveEmail "CV", Subject
ElseIf InStr(1, Item.Subject, "CN", vbTextCompare) > 0 Then
Prefix = "CN"
MoveEmail "CN", Subject
Else
Cancel = False
End If
End Sub
Private Sub MoveEmail(Prefix As String, Subject As String)
openingParen = InStr(Subject, Prefix)
closingParen = InStr(Subject, "]")
enclosedValue = Mid(Subject, openingParen, 8)
TestGetFolder (enclosedValue)
Set folder = GetFolder("\\Public Folders\All Public Folders\Projects\" & enclosedValue)
ObjCopy.Move folder
End Sub