It's not unusual for Outlook users to treat the calendar as a diary or journal, using it to store notes about a meeting. Brian wanted to know how to automate it - with a start and end button to record the time.
I'm looking for a macro that would have a start and stop button; when pressing the start button the macro would record what time it is; when pressing the stop button it would record what time it is again; then create a new appointment item on the calendar, push both of those fields (start time and end time) to a new appointment item on the calendar, and allow me to record the subject and notes and save the item.
The journal has a timer built into it, but we don't generally recommend using the journal because it is deprecated and may eventually be removed from Outlook.
It takes just a few lines of code to do this in an appointment. The first macro is one line and captures the current time, storing in it a global variable. The second macro creates the appointment form, using the stored variable as the Start time and Now as the End time. Create buttons on the main Outlook ribbon or Quick Access Toolbar (QAT) for each macro and it's ready to use.
When you add buttons to the QAT, they are available in all Outlook modules. When you customize the ribbon, the button is available only when working in that folder type.
Dim dStart As Date Sub startTime() dStart = Now End Sub Sub endTime() Dim oAppt As AppointmentItem Set oAppt = Application.CreateItem(olAppointmentItem) With oAppt .Start = dStart .End = Now .Display End With End Sub
Set the end time before closing
What if you want to take notes during the meeting or phone call? In that case, you can open the new appointment form first then use a macro to set the end time after the meeting ends. Add the Start button to the main Outlook ribbon or QAT and the End Time macro to the Appointment form's ribbon or QAT.
You don't actually even need a macro to do this, although it does save a few steps over the manual method:
- Open Appointment form
- Type Now in Start time field then tab out.
- When meeting ends, type Now in End time field then tab out.
Dim oAppt As AppointmentItem Sub ApptStart() Set oAppt = Application.CreateItem(olAppointmentItem) With oAppt .Start = Now .End = Now .Display End With End Sub Sub ApptEnd() oAppt.End = Now End Sub
Use a non-default calendar folder
This macro saves the diary events in a subfolder of the calendar. To use it with the selected calendar, change the Set otherFolder line to
Set otherFolder = Ns.Application.ActiveExplorer.CurrentFolder
The same method can be used with the first macro to save the events in a different folder.
Sub ApptStart() Dim Ns As Outlook.NameSpace Dim otherFolder As Outlook.Folder Set Ns = Application.GetNamespace("MAPI") 'Use a specifc folder or the current folder Set otherFolder = Ns.GetDefaultFolder(olFolderCalendar).Folders("Test") Set oAppt = otherFolder.Items.Add(olAppointmentItem) With oAppt .Start = Now .End = Now .Display End With End Sub Sub apptEnd() oAppt.End = Now End Sub
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, itâs at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
more
Hi Diane, not sure if this forum is the most appropriate for my question, but I was searching for "vba create journal from selected meeting" and ended up here. Given that the keyboard shortcuts to create a journal entry for the selected item is no longer available in latest versions of Office, I was hoping I could find a macro that I could assign a shortcut to, that would do the following:
Create a Journal entry for the selected Meeting, Appointment, or Mail... and auto populate the Subject of the Journal entry with the subject of the selected item, the Start Date and Time of the Journal entry with the Date and Time of the selected item (Mail, Meeting, or Appointment), and the Duration of the Journal Entry with the duration of the selected Meeting or Appointment.
Categories/Entry Types could be entered manually.
You rock! what if i want to save the appointment to a different calendar than the default calendar?
You'll need to use the add method - it's used in this macro at https://www.slipstick.com/developer/code-samples/create-tasks-task-folders/
You'd add this to replace the Set oappt line:
Dim Ns As Outlook.NameSpace
Dim otherFolder As Outlook.Folder
Set Ns = Application.GetNamespace("MAPI")
Set otherFolder = Ns.GetDefaultFolder(olFolderCalendar).Folders("Test")
Set oAppt = otherFolder.Items.Add(olAppointmentItem)
to have it work with the selected folder, use this to identify the folder
Set otherFolder = Ns.Application.ActiveExplorer.CurrentFolder