insert Date & Time (HH:mm) no (ss) in userform

Status
Not open for further replies.

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hi

I have a userform in outlook.

In the code of the form I have the following code:

Sub Datum_Click()

Item.Body = Item.Body & vbCrLf & Date() & " - " & Time() & ": "
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.SendKeys("{TAB 11}")
objWSHShell.SendKeys("^{End}")
objWSHShell.SendKeys("^{backspace}")

End Sub

I have button in the form that starts this code.

Date - time is inserted at the end of the form body.

Date is ok but in time format I do not need seconds.

Can you help me with the correct code to insert date - hh:mm. no seconds.

regards

witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to use Format(time, "hh:mm") - for 12 hour time, use Format(Time, "h:mm am/pm")

BTW, is your account working ok? I made a boo-boo last night when i was working on the forum and had to restore from a backup then restore posts and accounts created between the backup and the boo-boo - the accounts are giving me fits.
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
THX Diane
I tried


Item.Body = Item.Body & vbCrLf & Date() & " - " & Format(time, "hh:mm") & ": "
in the code of the outlook form


when I press the button I get an error :


Typenkonflikt: 'Format'

is the code working in your outlook form?

 

Forum Admin

Senior Member
It works in VB :) But not in vbsript, which is in the View Code dialog in a custom form.

The works in the view code dialog - FormatDateTime(Time,4) but its in 24 hr time. a 3 will use the long time format in Control panel.

If you need 12 hour format, you can use a function -

Code:
Function timeStamp()
If Hour(now) > 12 then timeStamp = Hour(now)-12 & ":" & Minute(now) & " PM"  else timeStamp = Hour(now) & ":" & Minute(now) 
 
End Function
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
THX Forum Admin - That is the solution
I have now:

Item.Body = Item.Body & vbCrLf & Date() & " - " & FormatDateTime(Time,4) & ": "
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.SendKeys("{TAB 11}")
objWSHShell.SendKeys("^{End}")
objWSHShell.SendKeys("^{backspace}")

SOLVED many THX :)

Witzker

PS: by the way is there a better way to place the cursor at the end of the body to the inseted date & Time??

schould I open a seperate Thread?

regards
Witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: insert Date & Time (HH:mm) no (ss) in userform

This thread is fine since it applies to this macro.

It's no worse than any other method, since Outlook's VBA doesn't cover cursor position.

The other option is using word object - - this is the block I use in macros but it won't work in vbscript.

Dim olInspector As Outlook.Inspector

Dim olDocument As Word.Document

Dim olSelection As Word.Selection

Set olInspector = Application.ActiveInspector()

Set olDocument = olInspector.WordEditor

Set olSelection = olDocument.Application.Selection

olSelection.InsertBefore 'or .InsertAfter
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Re: insert Date & Time (HH:mm) no (ss) in userform

Many THX
Witzker
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A insert Date & Time in userform Using Outlook 3
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
C Insert a Date Picker for Send Mail Subject Using Outlook 1
C Insert date in Subject through date picker Using Outlook 0
J Form design - how do I insert an automatic date/time field? Using Outlook 2
F Insert date at cursor location Outlook VBA and Custom Forms 4
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
B Programmatically force html send and insert clipboard contents into body Outlook VBA and Custom Forms 0
P Insert link in email body to attached document in Outlook 365 Outlook VBA and Custom Forms 0
E Copy e-mail body from outlook and insert into excel Outlook VBA and Custom Forms 3
R How Do I insert images in and Auto Reply Using Outlook 3
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
Diane Poremsky Create Task or Appointment and Insert Selected Text New Slipstick.com Articles 0
B Insert Hyperlinks for attachments in Userform Outlook VBA and Custom Forms 5
D Outlook task insert Outlook VBA and Custom Forms 3
A Auto Insert of filename when selecting 'Remove Attachment' Using Outlook 1
K Insert screenshots issue Using Outlook 2
makinmyway Recent Files Not Updating when Using Insert Hyperlink in Outlook 2013 Using Outlook 0
L Insert Photo to Contact Using Outlook 23
K OL2010 Button to Insert First Name Outlook VBA and Custom Forms 6
K OL2010 Button to Insert First Name Using Outlook 1
K Macro to insert attachments Using Outlook 1
mrje1 Opening a task the Insert Tab Option is not showing up and organizing Tasks Using Outlook 9
H Insert Specific Text before Subject for New mails and reply Using Outlook 3
R insert picture tab grey Using Outlook 1
K Outlook insert clip art, no results found...address book contacts only show up Using Outlook 5
M Can I insert pictures from a url address (from web) without downloading ? Using Outlook 1
M Insert clip art, shapes, smart art, chart and screenshot greyed out in OUTLOOK 2010 Using Outlook 2
T My Outlook 2007 - (Public folder-Calendar can't insert to My Favourite)but other calender can insert Using Outlook 1
R Outlook 2003: Insert, Item: Unable to insert an old email into a new email Using Outlook 2
L Outlook 2010 Insert file issue Using Outlook 1
Y Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 1
C Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 1
G enter key and space bar key insert characters into email Using Outlook 1
B How do I Insert a hyperlink (to company network) in an appointment in Outlook to distribute to attendees? Using Outlook 1
F Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 2
L Outlook 2010: cannot insert tables or illustrations Using Outlook 14
S Insert 'Requested By' into Task entry Using Outlook 1
B Insert your business card into your email signature in Outlook Using Outlook 2
G How do I find/open Address Book in Windows7 and insert my Outlook Contacts? Using Outlook 3
T Outlook2003 can't insert object Using Outlook 4
M insert picture in body of email Using Outlook 1
K "out of memory error" when user tries to insert an attachment to an outgoing email. Using Outlook 1
N Insert Signature Manually Using Outlook 1
S Error 'outlook cannot launch an application to handle d:\xxxxxx' when try to insert file. Using Outlook 1
K When trying to insert contacts in an email I get the following message: 'Can't contact LDAP Directory Server (81)' Using Outlook 1
R Red x when trying to insert picture into an email since upgrading to Office 2010 Using Outlook 2
R how to insert link to website for e.g. www.xyz.co.in in new email messages. Pl. tell me Using Outlook 2
B Insert Clip Art into HTML message - find picture formatting toolbar too? Using Outlook 6
Similar threads


















































Top