assign unique number email

Status
Not open for further replies.

zemestan

Member
Outlook version
Outlook 2007
Email Account
POP3
hello

we used outlook for send/recieve letters and message in our company

i have a question:

we need to assign one unique number to each mail/message.so that ID used for mail Identification.

this is for future refrence and search

this option can be outlook or in other Office App. that related with outlook...

Is there a solution..??

with thanks
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You'll need to use VBA to do it. Do you need to increment the number? You can use a text file and vba in all office apps can get the number from it.

This is the code snippet i use for an invoice # - it's incremented after each use.

Code:
Dim enviro As String 
 
enviro = CStr(Environ("USERPROFILE")) 
 
Invoice = System.PrivateProfileString(enviro & "\Templates\invoice-number.txt", _
       "MacroSettings", "Invoice") 
 
If Invoice = "" Then
   Invoice = 1 
 
Else
   Invoice = Invoice + 1 
 
End If 
 
System.PrivateProfileString(enviro & "\Templates\invoice-number.txt", "MacroSettings", _
       "Invoice") = Invoice
 

apugarte

Member
I Tried to copy this onto this code...

Public WithEvents myOlApp As Outlook.Application

Private Sub Application_Startup()
Initialize_Handler

End Sub

Public Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")

End Sub

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Subject, "Privacy", vbTextCompare) = False Then
Item.Subject = "Privacy " & Item.Subject
End If

End Sub

As you may imagine I need to assign a unique number to every message I send... but I couldn't figure out what to remove or where to insert the code ...

Can you help me???

Thanks!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The invoice code is word code and it needs tweaked to work in outlook - but what i thought i needed to do to tweak it, didn't work. :(

See Outlook Addins, Macros & Tips - VBOffice for one option. (Michael's Send macros are listed at Outlook VBA Macros - VBOffice )

Sequential numbers, stored in registry:

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim sAppName As String
Dim sSection As String
Dim sKey As String
Dim lRegValue As Long
Dim lFormValue As Long
Dim iDefault As Integer
sAppName = "Word 2000"
sSection = "Invoices"
sKey = "Current Invoice Number"
' The default starting number.
iDefault = 101
' Get stored registry value, if any.
lRegValue = GetSetting(sAppName, sSection, sKey, iDefault)
' If the result is zero, set to default value.
If lRegValue < 100 Then lRegValue = iDefault
' Increment and update invoice number.
SaveSetting sAppName, sSection, sKey, lRegValue + 1

Errhandler:
If Err <> 0 Then
MsgBox Err.Description
End If


Item.Subject = CStr(lRegValue) & Item.Subject

End Sub

for random numbers, try this:

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

intHighNumber = 10000

intLowNumber = 1
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Item.Subject = intNumber & Item.Subject

End Sub

This one does 5 random characters (alphanumberic)

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Item.Subject = GetRandom(5) & Item.Subject ' change 5 to another number for longer key

End Sub

Function GetRandom(Count)
Randomize
For i = 1 To Count
If (Int((1 - 0 + 1) * Rnd + 0)) Then
GetRandom = GetRandom & Chr(Int((90 - 65 + 1) * Rnd + 65))
Else
GetRandom = GetRandom & Chr(Int((57 - 48 + 1) * Rnd + 48))
End If
Next

End Function
 
Last edited:

apugarte

Member
Thank you so much...




Yesterday the first code worked fine... Today I received an error on this line:




Set myOlApp = CreateObject("Outlook.Application")




(The error - 2146959355 (8008005), it says that probably I need to reinstall my program)




So I couldn't try your suggestion :(




I am using this exactly:





Public WithEvents myOlApp As Outlook.Application



Private Sub Application_Startup()
Initialize_handler


End Sub



Public Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")


End Sub



Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

If InStr(1, Item.Subject, "Privacy", vbTextCompare) = False Then
Item.Subject = "Privacy " & Item.Subject
End If


End Sub






Any suggestions????
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I don't think you need to reinstall. Does the error say anything besides the code?
 

apugarte

Member
It says somethin like this:

Maybe the program which created the attachment is not installed properly or been moved or deleted. Reinstall the program (I have a spanish OL version)
 

jrobertson1983

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Item.Subject = GetRandom(5) & Item.Subject ' change 5 to another number for longer key

End Sub

Function GetRandom(Count)
Randomize
For i = 1 To Count
If (Int((1 - 0 + 1) * Rnd + 0)) Then
GetRandom = GetRandom & Chr(Int((90 - 65 + 1) * Rnd + 65))
Else
GetRandom = GetRandom & Chr(Int((57 - 48 + 1) * Rnd + 48))
End If
Next

End Function


Hi Diane - learning so much from you. I tried to copy and paste the code above, but when I go to run the Macro, GetRandom or myOIApp_ItemSend does not show up? I am running outlook 2016 on an exchange server, is there something I can update in the code so it's read by Outlook 2016?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Functions are called from other macros and item send (and other automatic macros) are not listed in the macro picker as you can't run them manually.

Did you put the itemsend macro in ThisOutlookSession? That's all you need to do.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Assign a unique number to every message I send Using Outlook 0
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
R Assign Categories "Round Robin" style but in a shared mailbox but on specific emails only Outlook VBA and Custom Forms 8
P Auto assign shared mailbox Outlook VBA and Custom Forms 1
D Assign categories to outgoing emails Outlook VBA and Custom Forms 0
F How to assign a task to a public task folder? Using Outlook 1
A How to assign the value returned by the regex execute function to a variable? Using Outlook 1
soadfan assign category (VBA) Using Outlook 7
Diane Poremsky Assign one task to several people Using Outlook 0
Diane Poremsky Assign an Email Account to an Outlook Contact Using Outlook 0
E for Mac: Assign Task not available!? Using Outlook 1
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
J Assign a signature by external or internal reciepents. Outlook VBA and Custom Forms 1
P VBA to assign category on calendar item does not work ?? why ?? Outlook VBA and Custom Forms 5
S assign task programmatically Outlook VBA and Custom Forms 2
C Cannot assign a task from a public folder? Outlook VBA and Custom Forms 4
C Assign To and CC list while using Redemption.dll library Outlook VBA and Custom Forms 10
C How to assign icon to a button in Outlook Add-in Outlook VBA and Custom Forms 1
S Unique ID solution for all outlook items? Outlook VBA and Custom Forms 2
A UID field in iCal files - unique per-event or per-user or both? Using Outlook 2
M Nested distribution lists: how to count UNIQUE # of people... Outlook VBA and Custom Forms 13
J Grouping email subjects by unique indentifier Using Outlook 1
M Creating a unique appointment for later amendment Outlook VBA and Custom Forms 1
H Email unique id Outlook VBA and Custom Forms 12
U Export of Message Header / Unique ID to Excel Sheet When email is Outlook VBA and Custom Forms 1
T Increasing the number of items that appear on the Categories list Using Outlook 2
TomHuckstep Outlook 2016 Limit the number of days syncing from Google Calendar Using Outlook 1
F How to create phone number as links in notes of Contacts Using Outlook 2
I Outlook 2016 Outlook Requesting Phone Number??? Using Outlook 1
C Calculating Week Number into a TextBox Outlook VBA and Custom Forms 0
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
O How to display number of items per .pst file Using Outlook 7
S Show Total Number Of Items Not Displaying Using Outlook 9
I Identify Number of email messages opened Outlook VBA and Custom Forms 7
J Saving attachments from specific sender (phone number) to specific folder on hard drive Using Outlook 3
J How to Fix “Encounter a large number of conflict items in Exchange OST file” Using Outlook 2
S Subject add ticket number from URL query Outlook VBA and Custom Forms 2
Diane Poremsky Add a file number or keyword to the subject line of messages Using Outlook 0
K Append subjectline based on number Using Outlook 4
B ...administrator has limited the number of items you can open simultaneously Outlook VBA and Custom Forms 7
snhnic Macro that does not overwrite but add a number Outlook VBA and Custom Forms 1
L Outlook 2007 Fix Phone Number Using Outlook 19
A Calendar List View Showing Week Number Using Outlook 1
neobite Maximum number of Exchange accounts in an Outlook profile Using Outlook 4
P Country name no longer shows in Phone number popup? Using Outlook 5
Edaniels Adding Week Number on Calender Using Outlook 2
P Outlook 2013 Phone Number Format Using Outlook 0
D Journal problem recording correct phone number Using Outlook 7
S Outlook - Reset the number of day-events Using Outlook 0
M Automatically highlight unread mail in Favorites inbox(s) (Blue number) Using Outlook 1

Similar threads

Top