Discussion:
Insert date at cursor location
(too old to reply)
F.H. van Zelm
2009-07-20 11:10:03 UTC
Permalink
Hi,

Once, I had a macro to inert the current date anywhere in the notes field of
an open item.
That macro has ... gone with the wind.

I recreated:
=====================================
Sub DateInsert()
Dim myOlApp As New Outlook.Application
Dim myItem As Object
Set myItem = myOlApp.ActiveInspector.CurrentItem
myItem.Body = Date & vbCr & myItem.Body
Set myItem = Nothing
Set myOlApp = Nothing
End Sub

=====================================
It works but, of course, inserts the date on top of any text.

What to write to make the time stamp appear at the cursor?

Many thanks, Frans
www.fhvzelm.com
Sue Mosher [MVP]
2009-07-20 12:10:48 UTC
Permalink
In what kind of item? In what version of Outlook?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by F.H. van Zelm
Hi,
Once, I had a macro to inert the current date anywhere in the notes field
of an open item.
That macro has ... gone with the wind.
=====================================
Sub DateInsert()
Dim myOlApp As New Outlook.Application
Dim myItem As Object
Set myItem = myOlApp.ActiveInspector.CurrentItem
myItem.Body = Date & vbCr & myItem.Body
Set myItem = Nothing
Set myOlApp = Nothing
End Sub
=====================================
It works but, of course, inserts the date on top of any text.
What to write to make the time stamp appear at the cursor?
Many thanks, Frans
www.fhvzelm.com
F.H. van Zelm
2009-07-20 12:48:18 UTC
Permalink
Hi Sue,

Outlook 2003, 'stand alone', not server * client

My former code worked on any type of item: contact, appointment, mail.
It would insert the current date at the cursor.

Annoyance with my 'new' code is also that it gives the security warning
whereas my former code worked without.

Kind regards, Frans
Post by Sue Mosher [MVP]
In what kind of item? In what version of Outlook?
--
Sue Mosher, Outlook MVP
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by F.H. van Zelm
Hi,
Once, I had a macro to inert the current date anywhere in the notes field
of an open item.
That macro has ... gone with the wind.
=====================================
Sub DateInsert()
Dim myOlApp As New Outlook.Application
Dim myItem As Object
Set myItem = myOlApp.ActiveInspector.CurrentItem
myItem.Body = Date & vbCr & myItem.Body
Set myItem = Nothing
Set myOlApp = Nothing
End Sub
=====================================
It works but, of course, inserts the date on top of any text.
What to write to make the time stamp appear at the cursor?
Many thanks, Frans
www.fhvzelm.com
Sue Mosher [MVP]
2009-07-20 20:13:22 UTC
Permalink
A statement like this

Dim myOlApp As New Outlook.Application

should never appear in an Outlook VBA macro. Instead, to avoid security
prompts, you need to use the intrinsic Application object:

Set myOlApp = Application

The Outlook object model itself has no techniques for inserting data at the
insertion point. For mail/post items, your options depend on whether you're
using the Outlook editor or the Word editor. For other items, you can try
automating the toolbar commands using code like that at
http://www.outlookcode.com/threads.aspx?forumid=1&messageid=6872, but I
haven't had good results with that myself. Or, use the methods of the
SafeInspector object from the third-party Outlook Redemtion library.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

ms,
Post by F.H. van Zelm
Hi Sue,
Outlook 2003, 'stand alone', not server * client
My former code worked on any type of item: contact, appointment, mail.
It would insert the current date at the cursor.
Annoyance with my 'new' code is also that it gives the security warning
whereas my former code worked without.
Kind regards, Frans
Post by Sue Mosher [MVP]
In what kind of item? In what version of Outlook?
Post by F.H. van Zelm
Hi,
Once, I had a macro to inert the current date anywhere in the notes
field of an open item.
That macro has ... gone with the wind.
=====================================
Sub DateInsert()
Dim myOlApp As New Outlook.Application
Dim myItem As Object
Set myItem = myOlApp.ActiveInspector.CurrentItem
myItem.Body = Date & vbCr & myItem.Body
Set myItem = Nothing
Set myOlApp = Nothing
End Sub
=====================================
It works but, of course, inserts the date on top of any text.
What to write to make the time stamp appear at the cursor?
Many thanks, Frans
www.fhvzelm.com
Alan Moseley
2009-07-21 15:13:02 UTC
Permalink
What about this?

Public Sub InsertDate()
SendKeys Date()
End Sub

It's a bit pants and you might want to do some checking before the sendkeys
runs, but it might work for you.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.
Post by F.H. van Zelm
Hi,
Once, I had a macro to inert the current date anywhere in the notes field of
an open item.
That macro has ... gone with the wind.
=====================================
Sub DateInsert()
Dim myOlApp As New Outlook.Application
Dim myItem As Object
Set myItem = myOlApp.ActiveInspector.CurrentItem
myItem.Body = Date & vbCr & myItem.Body
Set myItem = Nothing
Set myOlApp = Nothing
End Sub
=====================================
It works but, of course, inserts the date on top of any text.
What to write to make the time stamp appear at the cursor?
Many thanks, Frans
www.fhvzelm.com
Loading...