Get the seconds with userproperties.add method VBA Outlook

Status
Not open for further replies.

Nravota

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Hi Everyone and thanks in advance for your help,

I am trying to create a user-defined custom field with the userproperties.add method in vba outlook.

The idea is that when the user clicks on a macro button the field will show the current time with seconds included. I made the user-defined field with VBA Outlook but It gives the time with the following format, e.g. Thu 05/11/2015 09:23. I want to see the seconds as well

I created another user-defined field with Settings -> Columns -> ADD -> Test 1 with the idea to format UserDefinedFieldName to give the seconds. On the column properties I added: Format([UserDefinedFieldName],"ddd yyyy-mm-dd hh:mm:ss"). However it gives 0 seconds, which is not correct: Thu 05/11/2015 09:23:00.

How can I make a userdefined field which can give the seconds? Here is the code:

Code:
Dim UserDefinedFieldName As String
 
Set Folder = ActiveExplorer.CurrentFolder
 
If Folder.DefaultItemType = olMailItem Then
                Set Selection = ActiveExplorer.Selection
                    If Selection.Count > 0 Then
                        For i = 1 To Selection.Count
                        Set oEmail = Selection(i)
                        Set objProperty = oEmail.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olDateTime)
                        objProperty.Value = Now()
                        oEmail.Save
                        End Sub

Please help me get the seconds! Any help will be much appreaciated!
 

Nravota

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Hi Diane,

I do not need two fields, I just looked for another way to solve this but it works only with non-user-defined columns such as received.

I am not sure what you mean by value, for the field created invba outlook I use the =now() formula only. I do not know how to properly format it to include seconds.
 

Nravota

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
I also tried
Code:
objProperty.Value = vbLongTime
But it gives: 02/01/1900 00:00 :(. Is there a way to show current time with seconds?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It's something with the oldatetime field type that it drops the seconds. Do you need it as a date time field? If oltext will do, this works:
objProperty.Value = Format(Now(), "mm/dd/yyyy hh:mm:ss AM/PM")
 
Status
Not open for further replies.
Top