|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PropertyChange event not working2003... but for some reason it doesn't. Thought I could just set the variable to the AppointmentItem and use the WithEvents. Any help is appreciated. Thanks, Matt (code below) Option Explicit Private WithEvents olDeletedItems As Items Private WithEvents myOlItems As Items Public WithEvents myAppItem As Outlook.AppointmentItem Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.GetNamespace("MAPI") Set olDeletedItems = objNS.GetDefaultFolder (olFolderDeletedItems).Items Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items Set objNS = Nothing End Sub Private Sub Application_Quit() Set olDeletedItems = Nothing End Sub Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) If InStr(1, Item.Subject, "Vacation") Then MsgBox Item.Subject End If Set Item = Nothing End Sub Private Sub myOlItems_ItemChange(ByVal Item As Object) Set myAppItem = Item End Sub Private Sub myAppItem_PropertyChange(ByVal Name As String) If Name = "Subject" Then MsgBox "yes" End If End Sub The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event. Maybe you should start at the beginning and explain what you're trying to do, in what version of Outlook. -- Show quoteHide quoteSue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Matt" <Matthew_Som***@yahoo.com> wrote in message news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... >I am trying to get the PropertyChange event to fire using MS Outlook > 2003... > but for some reason it doesn't. Thought I could just set the variable > to the > AppointmentItem and use the WithEvents. > Any help is appreciated. Thanks, Matt (code below) > > > Option Explicit > Private WithEvents olDeletedItems As Items > Private WithEvents myOlItems As Items > Public WithEvents myAppItem As Outlook.AppointmentItem > > > Private Sub Application_Startup() > > > Dim objNS As NameSpace > Set objNS = Application.GetNamespace("MAPI") > Set olDeletedItems = objNS.GetDefaultFolder > (olFolderDeletedItems).Items > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > Set objNS = Nothing > End Sub > > > Private Sub Application_Quit() > Set olDeletedItems = Nothing > End Sub > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > If InStr(1, Item.Subject, "Vacation") Then > MsgBox Item.Subject > End If > > Set Item = Nothing > End Sub > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > Set myAppItem = Item > End Sub > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > If Name = "Subject" Then > MsgBox "yes" > End If > > > End Sub > I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003 w/ Exchange What I'm trying to do is flag an appointment when the subject changes. (As you said, i had to change the subject twice to fire the propertychange event, thanks). Thanks, Matt Show quoteHide quote On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > The item has already changed before your code instantiates the myAppItem > object. Only if you change it a second time will you get that event. > > Maybe you should start at the beginning and explain what you're trying to > do, in what version of Outlook. > -- > Sue Mosher, Outlook MVP > Author of Microsoft Outlook 2007 Programming: > Jumpstart for Power Users and Administrators > http://www.outlookcode.com/article.aspx?id=54 > > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... > > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > 2003... > > but for some reason it doesn't. Thought I could just set the variable > > to the > > AppointmentItem and use the WithEvents. > > Any help is appreciated. Thanks, Matt (code below) > > > Option Explicit > > Private WithEvents olDeletedItems As Items > > Private WithEvents myOlItems As Items > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > Private Sub Application_Startup() > > > Dim objNS As NameSpace > > Set objNS = Application.GetNamespace("MAPI") > > Set olDeletedItems = objNS.GetDefaultFolder > > (olFolderDeletedItems).Items > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > Set objNS = Nothing > > End Sub > > > Private Sub Application_Quit() > > Set olDeletedItems = Nothing > > End Sub > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > If InStr(1, Item.Subject, "Vacation") Then > > MsgBox Item.Subject > > End If > > > Set Item = Nothing > > End Sub > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > Set myAppItem = Item > > End Sub > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > If Name = "Subject" Then > > MsgBox "yes" > > End If > > > End Sub- Hide quoted text - > > - Show quoted text - I'm afraid that's a task that is well beyond "just learning Outlook VBA." To
handle that scenario in VBA code would require either maintaining a record of all the subjects of all the appointments or writing a wrapper class module to handle events for any item that the user might change. Both are relatively advanced techniques. Your scenario is much more suited to an Outlook custom form, which can have VBScript code behind it to work with item-level events such as PropertyChange. If you want to explore that approach, see http://www.outlookcode.com/article.aspx?ID=35 for custom form basics and http://www.outlookcode.com/article.aspx?ID=38 for particulars on PropertyChange. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Matt" <Matthew_Som***@yahoo.com> wrote in message I am just learning Outlook VBA and am trying to get thenews:2b83303d-e452-47c5-b218-54e470cd2ea2@d32g2000yqh.googlegroups.com... hang of different objects and methods. I am running Outlook 2003 w/ Exchange What I'm trying to do is flag an appointment when the subject changes. (As you said, i had to change the subject twice to fire the propertychange event, thanks). Thanks, Matt Show quoteHide quote On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > The item has already changed before your code instantiates the myAppItem > object. Only if you change it a second time will you get that event. > > Maybe you should start at the beginning and explain what you're trying to > do, in what version of Outlook. > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... > > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > 2003... > > but for some reason it doesn't. Thought I could just set the variable > > to the > > AppointmentItem and use the WithEvents. > > Any help is appreciated. Thanks, Matt (code below) > > > Option Explicit > > Private WithEvents olDeletedItems As Items > > Private WithEvents myOlItems As Items > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > Private Sub Application_Startup() > > > Dim objNS As NameSpace > > Set objNS = Application.GetNamespace("MAPI") > > Set olDeletedItems = objNS.GetDefaultFolder > > (olFolderDeletedItems).Items > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > Set objNS = Nothing > > End Sub > > > Private Sub Application_Quit() > > Set olDeletedItems = Nothing > > End Sub > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > If InStr(1, Item.Subject, "Vacation") Then > > MsgBox Item.Subject > > End If > > > Set Item = Nothing > > End Sub > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > Set myAppItem = Item > > End Sub > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > If Name = "Subject" Then > > MsgBox "yes" > > End If > > > End Sub- Hide quoted text - > > - Show quoted text - On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote > I am just learning Outlook VBA and am trying to get the Figured out a way to capture the appointment event the first> hang of different objects and methods. I am running Outlook 2003 > w/ Exchange > > What I'm trying to do is flag an appointment when > the subject changes. (As you said, i had to change the subject > twice to fire the propertychange event, thanks). > > Thanks, > Matt > > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > > > > > The item has already changed before your code instantiates the myAppItem > > object. Only if you change it a second time will you get that event. > > > Maybe you should start at the beginning and explain what you're trying to > > do, in what version of Outlook. > > -- > > Sue Mosher, Outlook MVP > > Author of Microsoft Outlook 2007 Programming: > > Jumpstart for Power Users and Administrators > > http://www.outlookcode.com/article.aspx?id=54 > > > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > > 2003... > > > but for some reason it doesn't. Thought I could just set the variable > > > to the > > > AppointmentItem and use the WithEvents. > > > Any help is appreciated. Thanks, Matt (code below) > > > > Option Explicit > > > Private WithEvents olDeletedItems As Items > > > Private WithEvents myOlItems As Items > > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > > Private Sub Application_Startup() > > > > Dim objNS As NameSpace > > > Set objNS = Application.GetNamespace("MAPI") > > > Set olDeletedItems = objNS.GetDefaultFolder > > > (olFolderDeletedItems).Items > > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > > Set objNS = Nothing > > > End Sub > > > > Private Sub Application_Quit() > > > Set olDeletedItems = Nothing > > > End Sub > > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > > If InStr(1, Item.Subject, "Vacation") Then > > > MsgBox Item.Subject > > > End If > > > > Set Item = Nothing > > > End Sub > > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > > Set myAppItem = Item > > > End Sub > > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > > If Name = "Subject" Then > > > MsgBox "yes" > > > End If > > > > End Sub- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - time through by using the Items_Open and setting the appointment item to the ActiveInspector().CurrentItem..Here's the code Private Sub myOlItems_Open(Cancel As Boolean) Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem End Sub On Jul 9, 11:20 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote > On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote: Ok..I've been a VBA programmer for a while but still> > > > > > > I am just learning Outlook VBA and am trying to get the > > hang of different objects and methods. I am running Outlook 2003 > > w/ Exchange > > > What I'm trying to do is flag an appointment when > > the subject changes. (As you said, i had to change the subject > > twice to fire the propertychange event, thanks). > > > Thanks, > > Matt > > > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > > > > The item has already changed before your code instantiates the myAppItem > > > object. Only if you change it a second time will you get that event. > > > > Maybe you should start at the beginning and explain what you're trying to > > > do, in what version of Outlook. > > > -- > > > Sue Mosher, Outlook MVP > > > Author of Microsoft Outlook 2007 Programming: > > > Jumpstart for Power Users and Administrators > > > http://www.outlookcode.com/article.aspx?id=54 > > > > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com.... > > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > > > 2003... > > > > but for some reason it doesn't. Thought I could just set the variable > > > > to the > > > > AppointmentItem and use the WithEvents. > > > > Any help is appreciated. Thanks, Matt (code below) > > > > > Option Explicit > > > > Private WithEvents olDeletedItems As Items > > > > Private WithEvents myOlItems As Items > > > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > > > Private Sub Application_Startup() > > > > > Dim objNS As NameSpace > > > > Set objNS = Application.GetNamespace("MAPI") > > > > Set olDeletedItems = objNS.GetDefaultFolder > > > > (olFolderDeletedItems).Items > > > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > > > Set objNS = Nothing > > > > End Sub > > > > > Private Sub Application_Quit() > > > > Set olDeletedItems = Nothing > > > > End Sub > > > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > > > If InStr(1, Item.Subject, "Vacation") Then > > > > MsgBox Item.Subject > > > > End If > > > > > Set Item = Nothing > > > > End Sub > > > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > > > Set myAppItem = Item > > > > End Sub > > > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > > > If Name = "Subject" Then > > > > MsgBox "yes" > > > > End If > > > > > End Sub- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - > > Figured out a way to capture the appointment event the first > time through by using the Items_Open and setting the appointment > item to the ActiveInspector().CurrentItem..Here's the code > > Private Sub myOlItems_Open(Cancel As Boolean) > Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem > End Sub- Hide quoted text - > > - Show quoted text - fairly new to the Outlook VBA world...I can see that my code to handle this event is a little ubiquitous but it will have to do for now. Thanks again. Will check out those links. On Jul 9, 11:27 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote > On Jul 9, 11:20 am, Matt <Matthew_Som***@yahoo.com> wrote: Sue, Spoke to soon that doesn't work...Uable to capture the Items_Open> > > > > > > On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote: > > > > I am just learning Outlook VBA and am trying to get the > > > hang of different objects and methods. I am running Outlook 2003 > > > w/ Exchange > > > > What I'm trying to do is flag an appointment when > > > the subject changes. (As you said, i had to change the subject > > > twice to fire the propertychange event, thanks). > > > > Thanks, > > > Matt > > > > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > > > > > The item has already changed before your code instantiates the myAppItem > > > > object. Only if you change it a second time will you get that event.. > > > > > Maybe you should start at the beginning and explain what you're trying to > > > > do, in what version of Outlook. > > > > -- > > > > Sue Mosher, Outlook MVP > > > > Author of Microsoft Outlook 2007 Programming: > > > > Jumpstart for Power Users and Administrators > > > > http://www.outlookcode.com/article.aspx?id=54 > > > > > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > > > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... > > > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > > > > 2003... > > > > > but for some reason it doesn't. Thought I could just set the variable > > > > > to the > > > > > AppointmentItem and use the WithEvents. > > > > > Any help is appreciated. Thanks, Matt (code below) > > > > > > Option Explicit > > > > > Private WithEvents olDeletedItems As Items > > > > > Private WithEvents myOlItems As Items > > > > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > > > > Private Sub Application_Startup() > > > > > > Dim objNS As NameSpace > > > > > Set objNS = Application.GetNamespace("MAPI") > > > > > Set olDeletedItems = objNS.GetDefaultFolder > > > > > (olFolderDeletedItems).Items > > > > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > > > > Set objNS = Nothing > > > > > End Sub > > > > > > Private Sub Application_Quit() > > > > > Set olDeletedItems = Nothing > > > > > End Sub > > > > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > > > > If InStr(1, Item.Subject, "Vacation") Then > > > > > MsgBox Item.Subject > > > > > End If > > > > > > Set Item = Nothing > > > > > End Sub > > > > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > > > > Set myAppItem = Item > > > > > End Sub > > > > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > > > > If Name = "Subject" Then > > > > > MsgBox "yes" > > > > > End If > > > > > > End Sub- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > Figured out a way to capture the appointment event the first > > time through by using the Items_Open and setting the appointment > > item to the ActiveInspector().CurrentItem..Here's the code > > > Private Sub myOlItems_Open(Cancel As Boolean) > > Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem > > End Sub- Hide quoted text - > > > - Show quoted text - > > Ok..I've been a VBA programmer for a while but still > fairly new to the Outlook VBA world...I can see that > my code to handle this event is a little ubiquitous > but it will have to do for now. Thanks again. Will > check out those links.- Hide quoted text - > > - Show quoted text - event. Thought that opening an item would trigger that event but I guess not..Looks like there is no Items_Open method just an Item_Open method. Ok back to the drawing board. I will certainly look at those links now. The Items object has no Open event, so I'm not sure what you're
accomplishing there. Also, Application.ActiveInspector.CurrentItem returns only the item window currently visible or most recently accessed. It doesn't help you if (a) multiple appointments are open (that's where you need a wrapper class) and thus available for the user to change or (b) the user edits the subject right in the Calendar window. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Matt" <Matthew_Som***@yahoo.com> wrote in message Figured out a way to capture the appointment event the firstnews:0d790108-56f8-439e-b480-19cf9e18a0cb@24g2000yqm.googlegroups.com... time through by using the Items_Open and setting the appointment item to the ActiveInspector().CurrentItem..Here's the code Private Sub myOlItems_Open(Cancel As Boolean) Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem End Sub On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote: Show quoteHide quote > I am just learning Outlook VBA and am trying to get the > hang of different objects and methods. I am running Outlook 2003 > w/ Exchange > > What I'm trying to do is flag an appointment when > the subject changes. (As you said, i had to change the subject > twice to fire the propertychange event, thanks). > > Thanks, > Matt > > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote: > > > > > The item has already changed before your code instantiates the myAppItem > > object. Only if you change it a second time will you get that event. > > > "Matt" <Matthew_Som***@yahoo.com> wrote in message > > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com... > > > >I am trying to get the PropertyChange event to fire using MS Outlook > > > 2003... > > > but for some reason it doesn't. Thought I could just set the variable > > > to the > > > AppointmentItem and use the WithEvents. > > > Any help is appreciated. Thanks, Matt (code below) > > > > Option Explicit > > > Private WithEvents olDeletedItems As Items > > > Private WithEvents myOlItems As Items > > > Public WithEvents myAppItem As Outlook.AppointmentItem > > > > Private Sub Application_Startup() > > > > Dim objNS As NameSpace > > > Set objNS = Application.GetNamespace("MAPI") > > > Set olDeletedItems = objNS.GetDefaultFolder > > > (olFolderDeletedItems).Items > > > Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items > > > Set objNS = Nothing > > > End Sub > > > > Private Sub Application_Quit() > > > Set olDeletedItems = Nothing > > > End Sub > > > > Private Sub olDeletedItems_ItemAdd(ByVal Item As Object) > > > If InStr(1, Item.Subject, "Vacation") Then > > > MsgBox Item.Subject > > > End If > > > > Set Item = Nothing > > > End Sub > > > > Private Sub myOlItems_ItemChange(ByVal Item As Object) > > > > Set myAppItem = Item > > > End Sub > > > > Private Sub myAppItem_PropertyChange(ByVal Name As String) > > > > If Name = "Subject" Then > > > MsgBox "yes" > > > End If > > > > End Sub- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
Other interesting topics
Forward mail without using the default signature
Create Macro to move email to subfolder in inbox Auto forwarding - empty bodies Capture appointment change Outlook staying in memory Outlook 2007 SP2 Undable To Update Appoinment Properties. Move Incoming Emails based on Specific Words in Senders' Addresses to Corresponding Folders MAPI OpenMsgStore causing Date Modifed to change on a PST file Building a distribution list from Access Outlook 2003 ItemAdd event does not execute sometimes |
|||||||||||||||||||||||