![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
outlook 2007:
i would like to start a VBA code everytime i click to save (new or changed appointment? - so do ...) is this possible with vBA? |
#2
|
|||
|
|||
![]()
It's possible. You need to get a reference to the item that's opened and
then handle its Write() event. You get a NewInspector() event when an item is opened, that would let you get a handle to the item being opened. You get NewInspector() when you handle events for the Inspectors collection. So for VBA this would work: 1. Select the ThisOutlookSession class module. Add your code there. 2. Add this code: Private WithEvents colInsp As Outlook.Inspectors Private WithEvents oAppt As Outlook.AppointmentItem Private Sub Application_Startup() Set colInsp = Application.Inspectors End Sub Private Sub colInsp_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olAppointment Then boolStartup = True Set oAppt = Inspector.CurrentItem End If End Sub Private Sub oAppt_Write(Cancel As Boolean) ' whatever End Sub That will initialize things when Outlook starts up and whenever you open an appointment item you can then handle its Write() event. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Patrik" wrote in message ... outlook 2007: i would like to start a VBA code everytime i click to save (new or changed appointment? - so do ...) is this possible with vBA? |
#3
|
|||
|
|||
![]() thanks a lot! it's very simple if you know the code ... ;-) "Ken Slovak - [MVP - Outlook]" wrote: It's possible. You need to get a reference to the item that's opened and then handle its Write() event. You get a NewInspector() event when an item is opened, that would let you get a handle to the item being opened. You get NewInspector() when you handle events for the Inspectors collection. So for VBA this would work: 1. Select the ThisOutlookSession class module. Add your code there. 2. Add this code: Private WithEvents colInsp As Outlook.Inspectors Private WithEvents oAppt As Outlook.AppointmentItem Private Sub Application_Startup() Set colInsp = Application.Inspectors End Sub Private Sub colInsp_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olAppointment Then boolStartup = True Set oAppt = Inspector.CurrentItem End If End Sub Private Sub oAppt_Write(Cancel As Boolean) ' whatever End Sub That will initialize things when Outlook starts up and whenever you open an appointment item you can then handle its Write() event. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Patrik" wrote in message ... outlook 2007: i would like to start a VBA code everytime i click to save (new or changed appointment? - so do ...) is this possible with vBA? |
#4
|
|||
|
|||
![]()
where could/should i edit the code if i also want execute some code if the
item is deleted? (not only new/changed) "Ken Slovak - [MVP - Outlook]" wrote: It's possible. You need to get a reference to the item that's opened and then handle its Write() event. You get a NewInspector() event when an item is opened, that would let you get a handle to the item being opened. You get NewInspector() when you handle events for the Inspectors collection. So for VBA this would work: 1. Select the ThisOutlookSession class module. Add your code there. 2. Add this code: Private WithEvents colInsp As Outlook.Inspectors Private WithEvents oAppt As Outlook.AppointmentItem Private Sub Application_Startup() Set colInsp = Application.Inspectors End Sub Private Sub colInsp_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olAppointment Then boolStartup = True Set oAppt = Inspector.CurrentItem End If End Sub Private Sub oAppt_Write(Cancel As Boolean) ' whatever End Sub That will initialize things when Outlook starts up and whenever you open an appointment item you can then handle its Write() event. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Patrik" wrote in message ... outlook 2007: i would like to start a VBA code everytime i click to save (new or changed appointment? - so do ...) is this possible with vBA? |
#5
|
|||
|
|||
![]()
In Outlook 2007 you can use the Folder.BeforeItemMove() event. That passes
you a reference to the item being moved and the target folder the item is being moved to. If the target folder is Nothing then the item is being deleted. There's also a Cancel argument, set that to True in the event handler and that cancels the deletion. So you'd declare the Folder object: Private WithEvents oFolder As Outlook.Folder That exposes the event handler for BeforeItemMove() in the Declarations drop-down when oFolder is selected. You'd have to decide which folder to use, for example if the Calendar folder then your initialization code would have a line like this: Set oFolder = Application.GetNameSpace("MAPI").GetDefaultFolder( olFolderCalendar) -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "Patrik" wrote in message ... where could/should i edit the code if i also want execute some code if the item is deleted? (not only new/changed) |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Event loop when saving Task item in event handler | Mustafa | Add-ins for Outlook | 1 | August 8th 08 07:24 PM |
Inputting an event...Error comes back..Cannot Save Item | Adriana | Outlook - Calandaring | 0 | March 5th 07 09:12 PM |
Item.Save and Item.Close Script causes Outlook 2007 to Crash | Rayyan | Outlook - Using Forms | 6 | November 25th 06 04:14 AM |
How to change an item from a recurring Appointment item to an exception from VB code? | Dikbill | Outlook and VBA | 2 | July 13th 06 09:45 AM |
Cancel event not working with .NET code | Osi | Add-ins for Outlook | 1 | April 13th 06 03:26 PM |