PDA

View Full Version : Insert date with a macro



ZaphodQB
11-10-2012, 02:39 PM
I am sorry if this has already been answered, I searched and did not find anything, so if my search was faulty, once again I am sorry.

I am trying to find a macro I can use in outlook 2010 to insert the current time in the following format 4:35PM, into a email that I have open, being composed. I have to keep a daily journal, noting times that certain calls were made, and the results of those calls, over the course of an evening and then send that email at the end of the night.

It would sure make it easier to just hit CTRL+(whatever) to insert the time at the current cursor position. But this simple task proves tough to find the simple answer for.

Thank you for your help.

Crocus Crow
11-13-2012, 04:54 PM
I spent a few hours researching this and setting it up (it's quite tricky), but it's a working solution, at least in Outlook 2003.

Here is the code:
Public Sub InsertTime()
If TypeName(Application.ActiveWindow) = "Inspector" Then
SendKeys Format(Now, "h:Nn:SsAM/PM")
DoEvents
End If
End Sub

Put this code in a new Outlook module (Alt+F11 to open the Visual Basic editor and then Insert -> Module to create a new module).

Next, you need to customise the Toolbar of a new Outlook email window, NOT the main Outlook window. The following steps worked for me in Outlook 2003, however I can't test them in Outlook 2010. I followed the instructions at http://www.howto-outlook.com/howto/macrobutton.htm (Create a button on a Toolbar).

1. Start a new blank email and in its window click View -> Toolbars -> Customise.

2. In Commands tab, click Macros in the Categories list. You should see Project1.InsertTime (the name of the macro defined by the code above) in the Commands list on the right.

3. Drag and drop Project1.InsertTime onto the Toolbar of the new email window.

4. With Project1.InsertTime still selected on the Toolbar, click Modify Selection, and:
a) Change the Name property from Project1.InsertTime to "&Q Insert Time" without the quotes. The macro will be run by pressing the Alt+Q keys. Alt+Q is unused by any standard Outlook command.
b) Click Change Button Image and select a suitable image (icon).
c) Set the command to either Text and Image or Text Only (Always). I found that setting it to Text Only (in Menus), and pressing Alt+Q to run the macro produces a beep instead of running the InsertTime macro.

5. Test the macro by pressing Alt+Q in the new email window. The current time should be inserted at the cursor position.

6. Close the new email window - no need to save the changes.

7. Open a new email. Verify that the custom icon and command is present on its Toolbar and press Alt+Q to insert the current time at the cursor position.