A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

code for event: everytime i save an item ...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 3rd 08, 10:20 PM posted to microsoft.public.outlook.program_vba
Patrik
external usenet poster
 
Posts: 3
Default code for event: everytime i save an item ...

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  
Old December 4th 08, 03:55 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default code for event: everytime i save an item ...

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  
Old December 4th 08, 08:06 PM posted to microsoft.public.outlook.program_vba
Patrik
external usenet poster
 
Posts: 3
Default code for event: everytime i save an item ...


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  
Old December 4th 08, 08:14 PM posted to microsoft.public.outlook.program_vba
Patrik
external usenet poster
 
Posts: 3
Default code for event: everytime i save an item ...

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  
Old December 5th 08, 03:29 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default code for event: everytime i save an item ...

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 09:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.