Insert date at cursor location

Status
Not open for further replies.
F

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.

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
 
In what kind of item? In what version of Outlook?

Sue Mosher

"F.H. van Zelm" <fhvzelm@hotmail.com> wrote in message

news:O%238G4qSCKHA.3800@TK2MSFTNGP04.phx.gbl...
> 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
>
 
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

"Sue Mosher [MVP]" <suemvp@turtleflock.com> schreef in bericht

news:O4TeDQTCKHA.3724@TK2MSFTNGP05.phx.gbl...
> In what kind of item? In what version of Outlook?

> > Sue Mosher
> > >

> "F.H. van Zelm" <fhvzelm@hotmail.com> wrote in message
> news:O%238G4qSCKHA.3800@TK2MSFTNGP04.phx.gbl...
> > 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
> >


>
 
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

ms,

"F.H. van Zelm" <fhvzelm@hotmail.com> wrote in message

news:ufHQbAUCKHA.1376@TK2MSFTNGP02.phx.gbl...
> 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

> "Sue Mosher [MVP]" <suemvp@turtleflock.com> schreef in bericht
> news:O4TeDQTCKHA.3724@TK2MSFTNGP05.phx.gbl...
> > In what kind of item? In what version of Outlook?
>

>
>> "F.H. van Zelm" <fhvzelm@hotmail.com> wrote in message
> > news:O%238G4qSCKHA.3800@TK2MSFTNGP04.phx.gbl...
> >> 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
> >>

>

>>


>
 
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.

"F.H. van Zelm" wrote:


> 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

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
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
Witzker insert Date & Time (HH:mm) no (ss) in userform Using Outlook 6
A insert Date & Time in userform Using Outlook 3
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
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
J Macro to Insert a Calendar Outlook VBA and Custom Forms 8
M Replyall macro with template and auto insert receptens Outlook VBA and Custom Forms 1
Z 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 Using Outlook 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
J How do I view the ruler in an Outlook message and/or insert tabs? Using Outlook 7
L Forward Email and Insert Sender's Email address in body Outlook VBA and Custom Forms 3
D Insert Text and Send Outlook VBA and Custom Forms 1
D Re: How do i insert radio buttons in an email Outlook VBA and Custom Forms 1
G How to insert a json array into a calendar events Outlook VBA and Custom Forms 1
K insert text into current position of pointer in mailcompose Outlook VBA and Custom Forms 1
J Insert File Outlook VBA and Custom Forms 2
M Insert a File Outlook VBA and Custom Forms 3
G Task / Insert / Attach Item / Business Contact BCM (Business Contact Manager) 1
M Forward email as insert from button Outlook VBA and Custom Forms 1
B Simple way to insert file text - macro? Outlook VBA and Custom Forms 1
S How to insert a picture programatically Outlook VBA and Custom Forms 12
C insert a picture Outlook VBA and Custom Forms 1
J How do I scan and insert into Outlook 2007? Using Outlook 3
B Insert information to MailItem Outlook VBA and Custom Forms 1
D RE: How do you change the default insert file path in outlook? Using Outlook 11
D Insert Text via Macro in Outlook 2007 Outlook VBA and Custom Forms 2
T Is it possible to INSERT a string into email body via Shortcut. Outlook VBA and Custom Forms 2

Similar threads

Back
Top