Get current selection accross journal and calender view

K

KLAT

Hello,

I'm new to programming vba in outlook, so I need some help.

I would like to get date and possible time out of the currently
selected item and the currently selected item is from a calender view
or a journal view.
However I not able to get it working.

I have been using ThisOutlookSession to declare the following, based
on an article of Sue Mosher.

' code start
Option Explicit

Dim m_explevents As New ExplEvents

Private Sub Application_Startup()
m_explevents.InitExplorers Application
End Sub
' code end

and with ExplEvents I have the following code:

'Code start

Private WithEvets m_colExplorers as Outlook.Explorers
Private WithEvets m_objExplorers as Outlook.Explorer

Private Sub m_objExplorer_SelectionChange()
MsgBox "This is a SelectionChange"
' Here I need something that can determine which kind of item is
' selected and if possible get the current date and time out of
' that item.
End sub

' end code

I hope that someone is able to help me with this - thanks in advance
and happy new year

Keld
 
M

Michael Bauer

Hi Keld,
Private WithEvets m_colExplorers as Outlook.Explorers
Private WithEvets m_objExplorers as Outlook.Explorer

there is an character missing in each line:

Private WithEvents m_colExplorers as Outlook.Explorers
Private WithEvents m_objExplorers as Outlook.Explorer


A good starting point is the Object Browser (F2). Switch from <All
Libraries> to <Outlook>. With this browser you can see that the Explorer
object fires the SelectionChange event not only, but has also a
Selection property.

If Selection.Count>0 then Selection.Item(index) returns one of the
selected items. Some folders can have different item types, for that you
need to check the type of the returned item, e.g.:

Dim obj as object
dim oAppt as Outlook.AppointmentItem
Set obj=objExplorer.Selection(1)
If Typeof obj is Outlook.AppointmentItem Then
' The item is an appointment in the calendar
Set oAppt=obj
Debug.Print oAppt.Start ' Prints the start date in _
the direct window (strg-g)
Endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top