![]() |
|
#1
|
|||
|
|||
|
Hi,
I have a website from where I receive emails I have developed the system so that it automatically adds a unique ticketnr to the subject line like 201500001. And now I would like to ask if its possible to automatically add a tag to the email title for instance 2015DR00001 if people simply directly email to my emailadress. And then automatically increment on each NEW email. So a first email not a reply or something. Is this possible and if so how can I do this? I hope you can help me out here? |
|
#2
|
||||
|
||||
|
It should be possible provided you can identify the messages you want to tag with a rule to process them as they arrive. The following macros store the incremented tag number in the registry (so the count is only maintained on one PC). The process them checks to establish if the last word in the subject of the message is a tag in the format - 2015DR00001 (where the first four digits are the year and the last 5 the incrementing number). If the message is not a reply with 'RE:' at the start of the subject the tag is added to the end of the subject.
Put the code in a new Outlook VBA module and run the script 'AddTag' from the rule. I have included a macro to test the code on an existing message and another to remove the registry entry to reset the count after testing. Code:
Option Explicit
Sub TestProcess()
'Graham Mayor www.gmayor.com
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
AddTag olMsg
lbl_Exit:
Exit Sub
End Sub
Sub AddTag(olItem As Outlook.MailItem)
'Graham Mayor www.gmayor.com
If Not TagExists(olItem.Subject) Then
olItem.Subject = olItem.Subject & " - " & Year(Date) & "DR" & AddNumber
olItem.Save
End If
lbl_Exit:
Exit Sub
End Sub
Private Function TagExists(strSubject As String) As Boolean
'Graham Mayor www.gmayor.com
If Not Left(strSubject, 3) = "RE:" Then
strSubject = Mid(strSubject, InStrRev(strSubject, Chr(32)))
If IsNumeric(Left(strSubject, 4)) And _
IsNumeric(Right(strSubject, 5)) And _
InStr(5, strSubject, "DR") > 0 Then
TagExists = True
End If
End If
lbl_Exit:
Exit Function
End Function
Private Function AddNumber() As String
'Graham Mayor www.gmayor.com
Dim TagNum As Long
TagNum = GetSetting(appname:="E-Mail Tag", section:="Config", _
Key:="TagNumber", Default:="0")
TagNum = TagNum + 1
SaveSetting appname:="E-Mail Tag", section:="Config", _
Key:="TagNumber", setting:=TagNum
AddNumber = Format(TagNum, "00000")
lbl_Exit:
Exit Function
End Function
Sub ResetNumbering()
'Graham Mayor www.gmayor.com
DeleteSetting "E-Mail Tag"
lbl_Exit:
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
I allready run into the problems with the first assignment.
Put the code in a new Outlook VBA module and run the script 'AddTag' from the rule. How do I do this? I was looking online but I don't see andy VBA module inside my outlook. Please advise. |
|
#4
|
|||
|
|||
|
Ok. So now I found the developers tab. Yeah baby.
What's next? Put the code in a new Outlook VBA module and run the script 'AddTag' from the rule. How do I create a new VBA module and run the script 'AddTag' from the rule? Thanks |
|
#5
|
||||
|
||||
|
From the VBA editor (ALT+F11 will open it) Insert > Module. Paste the code into that module. - Although aimed at Word the process described at http://www.gmayor.com/installing_macro.htm is almost identical and may help.
As for creating a rule - https://support.office.com/en-za/art...7-a50704d66c59 One of the options is run a Script and the script you want to run is AddTag, which will almost certainly be the only script listed to select. Set conditions to identify the particular messages or it will tag all incoming messages. You can run the 'test' macro with a received message selected to test how it works.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#6
|
|||
|
|||
|
Hi,
I can't find this part: One of the options is run a Script and the script you want to run is AddTag, which will almost certainly be the only script listed to select. Set conditions to identify the particular messages or it will tag all incoming messages. You can run the 'test' macro with a received message selected to test how it works. Please advise? Thanks a bunch. Business Builder |
|
#7
|
||||
|
||||
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Undelivered emails help | marshy36 | Outlook | 0 | 02-18-2015 09:23 AM |
Can only see emails no later than two weeks old! HELP!
|
rdunlap | Outlook | 1 | 07-07-2014 11:04 AM |
| Are my emails gone? | hrockwel | Outlook | 0 | 04-25-2012 07:30 PM |
Outlook emails are marked as spam, but Gmail emails are not.
|
aquabob | Outlook | 1 | 07-28-2010 11:41 AM |
Emails Bcc
|
zizou | Outlook | 2 | 11-29-2005 07:02 AM |