UserProperties VBA to move message to another folder

Status
Not open for further replies.

mrmmickle1

Member
Outlook version
Outlook 2010 64 bit
Email Account
Office 365 Exchange
I have created a custom form that I use to document Reporting Categories.

These Categories are then concatenated and put into a UserProperty.

I would like to then use the Application_ItemSend Event in order to perform something similar to the following rule:

Apply the rule after I send the message with ‡ in the body and on this computer only move a copy to the Deliverable Folder

Note: I was initially concatenating the fields in my form into the body of the email like this....which actually worked... I would rather save these to a UserProperty in the mailItem so they are not visible. Initially this had worked when appending the "USERINPUT" to the end of the email.... until we encountered emails exceeding 32,767 the max allowable characters. In this case the above rule will not process..... So then I appended the "USERINPUT" to the front of the email which works fine .....however, I feel this is a sloppy method.

Code:
  'Input Report Specifications to end of email
    myText = "<font size= 1><font color=""White"">‡" _
    & Me.cboLOB & "‡" _
    & Me.cboSubLOB & "‡" _
    & Me.cboDelType _
    & "</font></font size>"
My Issue is that I want to perform a rule that is like this:

Apply the rule after I send the message when UserProperty("XYZ") Exists and on this computer only move a copy to the Deliverable Folder

I tried to do this with the following code. However, it freezes the Application when I have large attachments.
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim fld As UserProperty
Dim saveFldr As Folder
Dim cpyMail As MailItem

Set saveFlder = Application.GetNamespace("MAPI").Folders("HR Data Requests").Folders("New and Open Requests").Folders("Deliverable Tracking")

For Each fld In Item.UserProperties
    If fld.Name = "CDTReporting" Then
  
    Set cpyMail = Item.Copy
    cpyMail.Move saveFldr
  
    End If
  
Next fld

End Sub
I was wondering if there is a better way to accomplish this task....seeing as this issue doesn't seem to occur if I use an outlook rule. So I guess I am trying to figure out the code that the Outlook Rule is using to move the copy....seeing as this works without issue.


Here is my UserForm Code:
Code:
Private Sub cmdSendMail_Click()

    Dim myText      As String
    Dim cpyFolder   As Outlook.Folder
    Dim sntFolder   As Outlook.Folder
    Dim cpy        As Object
    Dim NewMail     As MailItem
    Dim oInspector  As Inspector
    Dim myUserProperty  As UserProperty
   
    'Set Mail Object
    Set oInspector = Application.ActiveInspector
    If oInspector Is Nothing Then
        MsgBox "No active inspector item present.", vbCritical, "MetLife - CDT Tracker"
        Exit Sub
    End If
   
    'Set Mail Item
    Set NewMail = oInspector.CurrentItem
   
    'Make Sure Email is Editable
    If NewMail.Sent Then
        MsgBox "This is not an editable email"
        Exit Sub
    End If
     
    'Check for Subject Line and Recipient
    If NewMail.Subject = "" Or _
        NewMail.To = "" Then
            MsgBox "Please Enter a Subject Line or Recipient(s)", vbCritical, "MetLife - CDT Tracker"
            Exit Sub
    End If
     
     'Ensure Reporting Data has been filled in accurately
     If Me.cboLOB = "" Or _
        Me.cboSubLOB = "" Or Me.cboSubLOB = "Please Select LOB" Or _
        Me.cboDelType = "" Then
            MsgBox "Please fill in all reporting fields.  They are mandatory!", vbCritical, "MetLife - CDT Tracker"
            Exit Sub
     End If
         
    'Input Report Specifications to end of email
    myText = "<font size= 1><font color=""White"">‡" _
    & Me.cboLOB & "‡" _
    & Me.cboSubLOB & "‡" _
    & Me.cboDelType _
    & "</font></font size>"
   
     Set myUserProperty = NewMail.UserProperties.Add("CDTReporting", olText)
     myUserProperty.Value = "Test Test Test"
   
    'Add Report Tracking Info to Email
    If oInspector.IsWordMail Then
         NewMail.HTMLBody = myText & NewMail.HTMLBody
    Else
        'No object model to work with. Must manipulate raw text.
        Select Case NewMail.BodyFormat
            Case olFormatPlain, olFormatRichText, olFormatUnspecified
                NewMail.Body = myText & NewMail.Body
            Case olFormatHTML
                NewMail.HTMLBody = "<p>" & myText & "</p>" & NewMail.HTMLBody
        End Select
       
    End If
           
    Unload Me 'Unload usrfrmCDT
    NewMail.Send 'Send Active Outlook Message
           
End Sub

Thank you for your time.
 

Attachments

mrmmickle1

Member
Outlook version
Outlook 2010 64 bit
Email Account
Office 365 Exchange
Michael,

Thanks so much for the reply.

I assume this would be used like this:

Code:
  Dim UserProp As UserProperty

  Set UsrProp = NewMail.UserProperties.Find("CDTReporting")
     If Not UsrProp Is Nothing Then
        MsgBox "UserProperty Exists....."
     Exit Sub
     End If

Any insight into how to fix the underlying issue I'm facing? Or ideas of how to create another workaround without entering the reporting data directly in the email in white font? I would like to clean this process up a little if possible...
 

mrmmickle1

Member
Outlook version
Outlook 2010 64 bit
Email Account
Office 365 Exchange
Here is a little more detail about the process:

The process works like this:

1. User Opens Email
2. User types in To, Subject, Body Text
3. User attaches any applicable reports to tthe email (Attachments are not added using itemadd)
4. User Clicks on a QAT shortcut that launches my userform
5. User fills in the 3 fields and hits the send button
6. The send button fires this code Private Sub cmdSendMail_Click()
7. This Event is fired : Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Line of code that gets stuck in # 7 : cpyMail.Move saveFldr

To help further clarify I have run two tests:

1. I tried to run the code with large files attached to the message.

The code freezes on this line as expected: cpyMail.Move saveFldr
Note:
a. When the code freezes the Email is still visible.
b. The Item has not been moved to my Sent Items

2. I ran the code with no files attached (Just a regular email message containing text)
Code runs as expected no issue....

I did notice that the copy that is moved into the "Deliverable Tracking" Folder is a draft.

This leads me to believe that I am not using the correct code to get my end result.

Ex. When a email is sent from outlook it goes into the Sent Items Folder (As Unread etc...)

I would like an exact copy of this item in my "Deliverable Tracking" Folder. (Not a draft or Unread Copy)

Is this possible to accomplish using VBA Code. As I mentioned in my previous post the rule that I have put together works to accomplish this need....

Apply the rule after I send the message with ‡ in the body and on this computer only move a copy to the Deliverable Folder

However, I would like to avoid actually putting text in the email. This is why I am trying to store it in the UserProperty. Hope this helps to clarify my dilemma.

Diane and Michael thanks for looking into my issue. I appreciate the assistance. If I can add the item to the folder using ItemAdd I think this would resolve my issue. Not so familiar with the Outlook Object Library. Most of my work is done in Excel and Access. I'm attempting to branch out...but there is of course a learning curve :)


Note: The attachment in the first post is not applicable to my Outlook Issue. This was copied and pasted on accident.
 

mrmmickle1

Member
Outlook version
Outlook 2010 64 bit
Email Account
Office 365 Exchange
Diane,

I wanted to circle back to this thread and thank you for your time and effort. I have been doing a lot of regression testing at work that it really eating away my time. I should have an opportunity to test this out early next week. I'll post back with my results. After an initial look at some of the additional documentation your link provides I believe this is the way to go. :)
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
N Get the seconds with userproperties.add method VBA Outlook Outlook VBA and Custom Forms 4
W Appointment userproperties disappear Outlook VBA and Custom Forms 4
J Storing userproperties to array Outlook VBA and Custom Forms 4
R How to search for blank userproperties field Outlook VBA and Custom Forms 4
M Assigning Values to Contact UserProperties Outlook VBA and Custom Forms 1
S UserProperties of MailItem object. Outlook VBA and Custom Forms 3
V Difference between UserProperties and ItemProperties? Outlook VBA and Custom Forms 4
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D.Moore VBA script fail after Office 365 update Using Outlook 8
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
G VBA Macro Calendar Printing Assistant 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
N VBA to delete duplicates by message-id on common pst for 2 or more emails Outlook VBA and Custom Forms 0
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
M VBA to auto forward message with new subject and body text Outlook VBA and Custom Forms 8
A Custom VBA to sort emails into folders Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
B Clear Offline Items (Mail Folder) via VBA Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
B Vba to monitor time to respond to emails using a shared mailbox Outlook VBA and Custom Forms 5
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
M VBA to send reminder email if no response Using Outlook 13
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
U Outbox Message Stuck after reading some MailItem Properties with VBA Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
Similar threads


















































Top