PDA

View Full Version : [SOLVED:] Getting rid of 'quotes' in sent items folder of outlook ?



Snooker
09-20-2013, 08:13 AM
This is my first time here, and wanted to know if there is any macro or code that will get rid of the 'quotes' you get on replied to emails in the sent items box of outlook

I have been given some code which might do this, but wanted the code to run automatically so that any new replied to messages in the sent items box would appear with non of the automatic quotes

This is the code I was given:-



Public Sub EditSenderNames()
Dim Sel As Outlook.Selection
Dim Item As Object
Dim i&

Dim ReplaceThis$, ReplaceBy$, PropertyName$
Dim OldValue$, NewValue$
'Replace this character: "
ReplaceThis = Chr(34)
'Replace by: empty
ReplaceBy = ""
'Property: Sender's name
PropertyName = Link of schemas (As I am new I can not include the web link here yet, sorry)
Set Sel = Application.ActiveExplorer.Selection
For i = 1 To Sel.Count
Set Item = Sel(I)
OldValue = Item.PropertyAccessor.GetProperty(PropertyName)
NewValue = Replace(OldValue, ReplaceThis, ReplaceBy)
If OldValue <> NewValue Then
Item.PropertyAccessor.SetProperty PropertyName, NewValue
Item.Save
End If
Next
End Sub


I am new to these macro's and vba code and was told that if it was triggered within the sent items event that it would work automatically

Can somebody please tell me if a macro etc has been done already regarding the above and if not how can we perhaps get this code to work automatically within a sent items event, and how do I go about getting it to run on my computer please, thanks ?

Snooker
09-21-2013, 05:51 AM
I have since got some code which almost works perfectly, in removing the 'quotes' for replied back to emails in the sent items folder using the Application_ItemSend event, but it always leaves just one email with 'quotes' as this event fires before the email is sent

In outlook 2007 in vba is there an event I can use after the email has been sent as I can not see one please ?

SamT
09-24-2013, 05:26 PM
Snooker, I have merged your twp threads because they both deal with the same problem.

Can you post the Code you now have that is working almost perfectly? If you click the # button you can paste the code in between the two Code tags and VBAExpress will format it for you like I did in your first post, I selected all the Code, then clicked #.

Snooker
09-25-2013, 06:52 AM
SamT, I have now got the code working fine, there is an event you can use after an email has been sent, it is the event which is fired when an email is added to the sent items folder, therefore my issue is now resolved, thanks

Snooker
09-25-2013, 07:06 AM
Here is the macro which will delete the 'Single Quotes' from replied back to emails, listed in the sent items folder, also this macro will delete 'single quotes' received in the email inbox as well, so the sent items box will not display sent to names in 'Single Quotes' anymore

Here is the macro tested on office/outlook 2007 which needs to be pasted into the thisoutlooksession folder and not a module etc, may also work for other versions of office/outlook as well once code is properly installed on the computer in the thisoutlooksession folder etc


'Declarations:
Private WithEvents SentItems As Outlook.Items
Private WithEvents Inbox As Outlook.Items


Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
Set Inbox = GetNS(olApp).GetDefaultFolder(olFolderInbox).Items
Set SentItems = GetNS(olApp).GetDefaultFolder(olFolderSentMail).Items
End Sub


Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function


Private Sub Inbox_ItemAdd(ByVal item As Object)
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim Itm As MailItem

Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)
For Each Itm In folder.Items
If InStr(1, Itm.To, "'", vbTextCompare) > 0 Then
Itm.To = Replace(Itm.To, "'", "")
Itm.Save
End If
Next
End Sub


Private Sub SentItems_ItemAdd(ByVal item As Object)
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim Itm As MailItem

Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderSentMail)
For Each Itm In folder.Items
If InStr(1, Itm.To, "'", vbTextCompare) > 0 Then
Itm.To = Replace(Itm.To, "'", "")
Itm.Save
End If
Next
End Sub

SamT
09-25-2013, 07:52 AM
Snooker, Thank you very much for sharing your solution. I marked the thread Solved so others can find the solution.

blinking
04-17-2014, 12:46 PM
Snooker or anyone... I'm a rank amateur at VB so please forgive my ignorance. Have copied your solution into ThisOutlookSession folder but for some reason, the single quotes are still appearing in the Sent To email field (the single quotes break up the sort and makes be batty when I'm trying to locate emails to a particular person)... and suggestions or advice would be greatly appreciated.

Snooker
04-17-2014, 04:37 PM
blinking, My solution will work with outlook 2007 and I think with "probably 2010" as well, but it does not work I have been told with 2013, so you need to have the correct version of office, again I tested it on office 2007, Please read this extra information below:-

In your email inbox folder and sent items folder the quotes should not be there anymore for when you sort your emails (But if you had a long email being sent back and forth I think the quotes may be seen on some of the attached emails but not from your main inbox and sent box folders

How To Create This Macro



To enable Macro's in outlook, open up outlook then on the Tools menu point to Macro and then click Secuity, you can then make your own choice, for example:- Warnings for all macros, or
No secuity check for macros (Not recommended), etc.
Save your choice
Then on the Tools menu again of your opened up outlook, point to Macro, and then click Visual Basic Editor.
In the top left box make sure the last item displayed is ThisOutlookSession:-
You may need to Double click on Project1
Double click on Micosoft Office Outlook
Double click ThisOutlookSession
Until you have the big main empty white window, copy and paste all the below code into this opened code window.
When you are finished pasting in the macro, Close down outlook, and during this time a box will pop up, and then click save to what you have just done (If at any time you are possibly asked for a name call it:- RemovingSingleQuotes), then when outlook is fully closed down, Re-Open Microsoft Office Outlook.
That's it finished, it may now hopefully work and work totally automatically from now on.


Private WithEvents SentItems As Outlook.Items
Private WithEvents Inbox As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
Set Inbox = GetNS(olApp).GetDefaultFolder(olFolderInbox).Items
Set SentItems = GetNS(olApp).GetDefaultFolder(olFolderSentMail).Items
End Sub

Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function

Private Sub Inbox_ItemAdd(ByVal item As Object)
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim Itm As MailItem

Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)
For Each Itm In folder.Items
If InStr(1, Itm.To, "'", vbTextCompare) > 0 Then
Itm.To = Replace(Itm.To, "'", "")
Itm.Save
End If
Next
End Sub

Private Sub SentItems_ItemAdd(ByVal item As Object)
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim Itm As MailItem

Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderSentMail)
For Each Itm In folder.Items
If InStr(1, Itm.To, "'", vbTextCompare) > 0 Then
Itm.To = Replace(Itm.To, "'", "")
Itm.Save
End If
Next
End Sub

Diakatarnis
09-08-2014, 02:40 AM
Hi,

I've tried using this code on Outlook 2013 to no avail, i'm having the problem where the same contact appears with ' around their names even though everything else is identical.

This code looked like it would be the holy grail but it doesn't seem to work in Outlook 2013.

Is there any way I can get this code to work? programming is not really my strong point so I'm not sure where the problem is :(

Many thanks

Snooker
09-08-2014, 03:54 AM
Diakatarnis, thanks for your post
Unfortunately it will not work with office 2013 only 2007 or "possibly 2010" as well
I did not like office 2013 and bought office 2007 as I think it is much better to use and looks good
So the only way is to get office 2007 to make sure it works for sure

Diakatarnis
09-08-2014, 05:00 AM
Diakatarnis, thanks for your post
Unfortunately it will not work with office 2013 only 2007 or "possibly 2010" as well
I did not like office 2013 and bought office 2007 as I think it is much better to use and looks good
So the only way is to get office 2007 to make sure it works for sure

Bum,

Unfortunately the machines I need to do this on have all just been upgraded the 2013 and I don't think the client will be happy if I say they have to downgrade back to 2007.


Is there no way of accomplishing this on 2013? or even any script that can order emails by email address instead of name?

westconn1
09-08-2014, 05:14 AM
Is there no way of accomplishing this on 2013?i am sure there would be, but i can not test on that version


even any script that can order emails by email address instead of name?again that should be quite possible, but again i can not test, as i do not have outlook 2013 and am unlikely to upgrade, just for testing code

Snooker
09-08-2014, 05:53 AM
Diakatarnis, I am not a vba developer and I only modified slightly the above code I was given, which I asked a vba developer to write for me for about £10 (vba freelance developer online), but like the last reply to you said, it may well be possible to get some code to work for office 2013, your best bet would be to try and find an online freelance vba developer and post on there forum exactly what you want and how much you are prepared to pay, I am sure they could help you in the same way I was helped for office 2007, they will write all the code and test it to make sure it works, hope this helps