VB vs VBA differences handling invites
Author |
Message |
Davi #1 / 4
|
 VB vs VBA differences handling invites
I wrote this function to automate the accept process on selected invites I get. It is working fine within outlookXP. see the code below. I tried to do the same thing from VB. I get error message "runtime error 91, object variable or with block variable not set". my last debug string says "testing the item ... class=53" which is the olMeetingRequest Help please thanks David The VB code: Private Sub AcceptSelectedInvites_Click() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim myclass As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") ' Set Sel = Application.ActiveExplorer.Selection Set Sel = myOlApp.ActiveExplorer.Selection ShowIt.AddItem "Number of selected items: " & Sel.Count For I = 1 To Sel.Count ShowIt.AddItem "Testing the items... Class= " & Sel.Item(I).Class myclass = Sel.Item(I).Class If myclass = olMeetingRequest Then ShowIt.AddItem "Handling the appointment ..." Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog ShowIt.AddItem "Item accepted!" End If Next End Sub The outlook VBA code that works Public Sub AcceptSelectedInvites() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set Sel = Application.ActiveExplorer.Selection For I = 1 To Sel.Count If Sel.Item(I).Class = olMeetingRequest Then Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog End If Next End Sub
|
Tue, 30 Nov 2004 07:40:37 GMT |
|
 |
neo [mvp outlook #2 / 4
|
 VB vs VBA differences handling invites
Not sure if this is the problem... but in your code you have declared myclass as an object, yet later you are trying to use it as something else.
I wrote this function to automate the accept process on selected invites I get. It is working fine within outlookXP. see the code below. I tried to do the same thing from VB. I get error message "runtime error 91, object variable or with block variable not set". my last debug string says "testing the item ... class=53" which is the olMeetingRequest Help please thanks David The VB code: Private Sub AcceptSelectedInvites_Click() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim myclass As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") ' Set Sel = Application.ActiveExplorer.Selection Set Sel = myOlApp.ActiveExplorer.Selection ShowIt.AddItem "Number of selected items: " & Sel.Count For I = 1 To Sel.Count ShowIt.AddItem "Testing the items... Class= " & Sel.Item(I).Class myclass = Sel.Item(I).Class If myclass = olMeetingRequest Then ShowIt.AddItem "Handling the appointment ..." Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog ShowIt.AddItem "Item accepted!" End If Next End Sub The outlook VBA code that works Public Sub AcceptSelectedInvites() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set Sel = Application.ActiveExplorer.Selection For I = 1 To Sel.Count If Sel.Item(I).Class = olMeetingRequest Then Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog End If Next End Sub
|
Thu, 02 Dec 2004 22:25:23 GMT |
|
 |
Davi #3 / 4
|
 VB vs VBA differences handling invites
i think tha VB could have handled the point you mentioned I figured out the error: In VB I did not have the "option explicit" statement (bad boy!) and hence all the ol* (example the olMeetingRequest) were not defined and at run time were 0.... How do I make VB recognize the outlook constants ??? Thanks David
Not sure if this is the problem... but in your code you have declared myclass as an object, yet later you are trying to use it as something else.
I wrote this function to automate the accept process on selected invites I get. It is working fine within outlookXP. see the code below. I tried to do the same thing from VB. I get error message "runtime error 91, object variable or with block variable not set". my last debug string says "testing the item ... class=53" which is the olMeetingRequest Help please thanks David The VB code: Private Sub AcceptSelectedInvites_Click() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim myclass As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") ' Set Sel = Application.ActiveExplorer.Selection Set Sel = myOlApp.ActiveExplorer.Selection ShowIt.AddItem "Number of selected items: " & Sel.Count For I = 1 To Sel.Count ShowIt.AddItem "Testing the items... Class= " & Sel.Item(I).Class myclass = Sel.Item(I).Class If myclass = olMeetingRequest Then ShowIt.AddItem "Handling the appointment ..." Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog ShowIt.AddItem "Item accepted!" End If Next End Sub The outlook VBA code that works Public Sub AcceptSelectedInvites() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set Sel = Application.ActiveExplorer.Selection For I = 1 To Sel.Count If Sel.Item(I).Class = olMeetingRequest Then Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog End If Next End Sub
|
Fri, 03 Dec 2004 04:04:40 GMT |
|
 |
neo [mvp outlook #4 / 4
|
 VB vs VBA differences handling invites
Add a reference to Microsoft Outlook via the Project | Reference menu selection.
i think tha VB could have handled the point you mentioned I figured out the error: In VB I did not have the "option explicit" statement (bad boy!) and hence all the ol* (example the olMeetingRequest) were not defined and at run time were 0.... How do I make VB recognize the outlook constants ??? Thanks David
Not sure if this is the problem... but in your code you have declared myclass as an object, yet later you are trying to use it as something else.
I wrote this function to automate the accept process on selected invites I get. It is working fine within outlookXP. see the code below. I tried to do the same thing from VB. I get error message "runtime error 91, object variable or with block variable not set". my last debug string says "testing the item ... class=53" which is the olMeetingRequest Help please thanks David The VB code: Private Sub AcceptSelectedInvites_Click() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim myclass As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") ' Set Sel = Application.ActiveExplorer.Selection Set Sel = myOlApp.ActiveExplorer.Selection ShowIt.AddItem "Number of selected items: " & Sel.Count For I = 1 To Sel.Count ShowIt.AddItem "Testing the items... Class= " & Sel.Item(I).Class myclass = Sel.Item(I).Class If myclass = olMeetingRequest Then ShowIt.AddItem "Handling the appointment ..." Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog ShowIt.AddItem "Item accepted!" End If Next End Sub The outlook VBA code that works Public Sub AcceptSelectedInvites() Dim myOlApp, myNameSpace As Object Dim myAddressList, myAddressEntries, myAddressEntry As Object Dim EmailAddress, UserName, Item, Sel, DestinationFolder, Apointment As Object Dim I, J, MyCount, response As Integer Dim FoundFlag As Boolean Dim DestinationFolderName As String Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set Sel = Application.ActiveExplorer.Selection For I = 1 To Sel.Count If Sel.Item(I).Class = olMeetingRequest Then Set Apointment = Sel.Item(I).GetAssociatedAppointment(True) Apointment.Respond olMeetingAccepted, True, False ' no dialog End If Next End Sub
|
Fri, 03 Dec 2004 08:36:42 GMT |
|
|
|