OL Kalender, suche

  • VB.NET

Es gibt 13 Antworten in diesem Thema. Der letzte Beitrag () ist von lris08.

    OL Kalender, suche

    Hallo,

    versuche gerade unter Hilfe von MSDN usw. einen Code zu schreiben, der mir Termine in Outlook sucht und dann halt ändern.

    Übersehe da irgendwas, da ich eine Fehlermeldung bekomme- habe wohl zu wenig geschlafen heute und sitze an dem gesamten Code (hier nur ein Teil) schon die halbe Nacht...

    Vielleicht könnt Ihr mir sagen, was ich da übersehe...

    VB.NET-Quellcode

    1. ...
    2. Dim olApp As Outlook.Application
    3. Dim termin As Outlook.AppointmentItem
    4. Dim objContacts As Outlook.MAPIFolder
    5. Dim objNameSpace As Outlook.NameSpace
    6. olApp = CreateObject("Outlook.Application")
    7. objNameSpace = olApp.GetNamespace("MAPI")
    8. objContacts = objNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
    9. For Each dt_calendar As DataRow In Database1DataSet.Tab_TerminBericht
    10. ' SuchStrings .... zum Testen
    11. Dim sucheTermin As String = "[BillingInformation]='T" & dt_calendar("TB_ID") & "'"
    12. Dim sucheStart As DateTime = dt_calendar("TB_TerminVon")
    13. Dim sucheEnde As DateTime = dt_calendar("TB_TerminBis")
    14. 'Bearbeitung / Neuerstellung eines Termins
    15. Try
    16. 'suche Nach vorhandenen und ggf. Ändern...
    17. termin = objContacts.Items.Find(sucheTermin)
    18. termin.ReminderSet = True
    19. termin.Duration = dt_calendar("TB_Dauer")
    20. termin.Start = dt_calendar("TB_Dauer")
    21. 'termin.Subject = RProw.RP_Firma & Name & " - " & RProw.RP_Termininfo
    22. 'termin.Location = RProw.RP_Adresse
    23. termin.BillingInformation = "T" & dt_calendar("TB_ID")
    24. 'termin.Body = ABC & Branche & Telefon & Mobil & _
    25. ' "Kundenmanager: Übernahme aus Reiseplanung." & _
    26. ' vbCrLf & "Kundenmanager/Outlook-ID: " & RProw.RP_OutlookID
    27. 'termin.Save()
    28. Catch ex As System.Exception
    29. MsgBox("! " & ex.Message)
    30. End Try
    31. Zaehler += 1
    32. BGW_Termine.ReportProgress(Zaehler)
    33. If BGW_Firmen.CancellationPending = True Then
    34. Exit Sub
    35. End If
    36. Next
    37. ...


    Fehlermeldung:
    Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

    was habe ich da übersehen?

    Lg lris
    Hast Du die richtige .NET-Outlook-Version eingebunden? Die sollte da stehen, wo Du die Snippets gefunden hast.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hallo, ja habe die richtige OL Vers eingebunden - mein Code über Kontakte finktioniert bereits bestens...


    ?Dim olApp as New Outlook.Application > new hats bei Dim olApp As New Outlook.Application nicht gebracht...


    Irgendwas habe ich da übersehen...
    wenn ich nur wüßte oder sehen würde was...

    VB.NET-Quellcode

    1. Dim olApp As New Outlook.Application
    2. Dim termin As Outlook.AppointmentItem
    3. Dim objContacts As Outlook.MAPIFolder
    4. Dim objNameSpace As Outlook.NameSpace
    5. olApp = CreateObject("Outlook.Application")
    6. objNameSpace = olApp.GetNamespace("MAPI")
    7. objContacts = objNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
    mit roten punkt ermittelt:

    bei diesem Code kommt die fehlermeldung...

    VB.NET-Quellcode

    1. Dim sucheTermin As String = "[BillingInformation]='T" & dt_calendar("TB_ID") & "'"


    sorry- falsche zeile aus dem Code kopiert...

    hier kommt der fehler

    VB.NET-Quellcode

    1. termin = objContacts.Items.Find(sucheTermin)
    sollte schon sein, gleicher Code nur halt mir Kontakten wird gefüllt, wüßt aber nicht wie ich das jetzt nachgucken könnt..

    aber selbst wenn nicht, sollt doch eigentlich die suchfunktion funtkionieren- halt nur kein ergebnis ausgeben ...

    oder?

    lris08 schrieb:

    wüßt aber nicht wie ich das jetzt nachgucken

    Haltepunkt setzen auf die Zeile und dann die Variable im Überwachungsfenster anschauen...
    ICh bin mir nicht sicher, du willst der Variable ja einen Wert zuweisen, evtl darf das halt nich der Rückgabewert sein, wenn findeTermin nicht vorhanden ist.
    ggf vor der zuweisung erst prüfen ob ein ergebnis zurückgeliefert wird von .find...
    habs hinbekommen...

    hier eine kleine Outlooksyncronisation... nocht nicht ganz fertig - brauch noch nen grob und feinschliff... aber funktioniert schon mal...
    code ist bestimmt recht ätzend, aber erst mal funzelt er...

    vielleicht kann das mal einer brauchen:

    VB.NET-Quellcode

    1. Private Sub Test()
    2. Dim Zaehler As Integer = 0
    3. ' Create Outlook Application
    4. Dim oApp As Outlook.Application = New Outlook.Application()
    5. ' Get Mapi NameSpace and Logon
    6. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
    7. ' Get all the appointments from Calendar folder
    8. Dim oCal As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    9. Dim oItems As Outlook.Items = oCal.Items
    10. Dim sSearch As String = Nothing
    11. Dim oAppointment As Outlook.AppointmentItem
    12. For Each dt_calendar As DataRow In Database1DataSet.Tab_TerminBericht
    13. ' Use Find method
    14. sSearch = "[BillingInformation]='T" & dt_calendar("TB_ID") & "'"
    15. 'The following statement uses the Find method of the Items collection object to
    16. 'return the first appointment whose Start field matches the criteria:
    17. oAppointment = oItems.Find(sSearch)
    18. If Not oAppointment Is Nothing Then
    19. oAppointment.Duration = dt_calendar("TB_Dauer")
    20. oAppointment.Start = dt_calendar("TB_TerminVon")
    21. 'oAppointment.End = dt_calendar("TB_TerminBis")
    22. oAppointment.Subject = _
    23. dt_calendar("TB_FirmaName") & ", " & _
    24. dt_calendar("TB_PersonName") & " - " & _
    25. dt_calendar("TB_Titel")
    26. oAppointment.Location = _
    27. dt_calendar("TB_TerminStrasse") & ", " & _
    28. dt_calendar("TB_TerminPlz") & " - " & _
    29. dt_calendar("TB_TerminOrt")
    30. oAppointment.BillingInformation = "T" & dt_calendar("TB_ID")
    31. oAppointment.Body = _
    32. "KD ABC: " & dt_calendar("TB_FirmaABC") & _
    33. "Branche: " & dt_calendar("TB_FirmaBranche") & vbCrLf & _
    34. "Kundenmanager: Übernahme aus Reiseplanung." & _
    35. vbCrLf & "Kundenmanager/Outlook-ID: " & dt_calendar("TB_ID")
    36. oAppointment.Save()
    37. Else
    38. MsgBox("2")
    39. Dim ooutlook As New Outlook.Application
    40. Dim termin As Outlook.AppointmentItem
    41. termin = ooutlook.CreateItem(Outlook.OlItemType.olAppointmentItem)
    42. termin.ReminderSet = False
    43. termin.Duration = dt_calendar("TB_Dauer")
    44. termin.Start = dt_calendar("TB_TerminVon")
    45. termin.End = dt_calendar("TB_TerminBis")
    46. termin.Subject = _
    47. dt_calendar("TB_FirmaName") & ", " & _
    48. dt_calendar("TB_PersonName") & " - " & _
    49. dt_calendar("TB_Titel")
    50. termin.Location = _
    51. dt_calendar("TB_TerminStrasse") & ", " & _
    52. dt_calendar("TB_TerminPlz") & " - " & _
    53. dt_calendar("TB_TerminOrt")
    54. termin.BillingInformation = "T" & dt_calendar("TB_ID")
    55. termin.Body = _
    56. "KD ABC: " & dt_calendar("TB_FirmaABC") & _
    57. "Branche: " & dt_calendar("TB_FirmaBranche") & vbCrLf & _
    58. "Kundenmanager: Übernahme aus Reiseplanung." & _
    59. vbCrLf & "Kundenmanager/Outlook-ID: " & dt_calendar("TB_ID")
    60. termin.Save()
    61. End If
    62. Next
    63. ' Logoff
    64. oNS.Logoff()
    65. ' Clean Up
    66. oApp = Nothing
    67. oNS = Nothing
    68. oItems = Nothing
    69. oAppointment = Nothing
    70. End Sub



    @ErfinderDesRades : bitte nicht schimpfen ! :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „lris08“ ()