Hi,
folgendes Problem: Ich habe ein Visual Basic Script erstellt, welches alle in Outlook gespeicherten Kontakte in eine Excel Tabelle schreibt.
Der Export funktioniert prima und einwandfrei.
Jedoch stellt sich der Import von der Excel nach Outlook etwas problematisch dar.
Hat jemand einen Tipp oder sogar die Lösung warum der bisherige Code nicht funktioniert ?
PS: Ich beschäftige mich noch nicht sehr lange mit Visual Basic, also verzeiht mir bitte solltet ihr blutige Anfängerfehler finden
Hier nun der bisherige Code:
*Topic verschoben, das ist kein VBScript*
folgendes Problem: Ich habe ein Visual Basic Script erstellt, welches alle in Outlook gespeicherten Kontakte in eine Excel Tabelle schreibt.
Der Export funktioniert prima und einwandfrei.
Jedoch stellt sich der Import von der Excel nach Outlook etwas problematisch dar.
Hat jemand einen Tipp oder sogar die Lösung warum der bisherige Code nicht funktioniert ?
PS: Ich beschäftige mich noch nicht sehr lange mit Visual Basic, also verzeiht mir bitte solltet ihr blutige Anfängerfehler finden
Hier nun der bisherige Code:
VB.NET-Quellcode
- Imports Outlook = Microsoft.Office.Interop.Outlook
- Imports Excel = Microsoft.Office.Interop.Excel
- Public Class FExport
- Dim olApp As Microsoft.Office.Interop.Outlook.Application
- Dim olNameSpace As Microsoft.Office.Interop.Outlook.NameSpace
- Dim olContactsFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
- Dim olAll As Microsoft.Office.Interop.Outlook.Items
- Dim olReal As Microsoft.Office.Interop.Outlook.Items
- Dim olContact As Microsoft.Office.Interop.Outlook.ContactItem
- Dim syncSuccess As Boolean
- Dim AllProcesses() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses()
- Dim MyProcess As System.Diagnostics.Process
- Dim strContactFilter As String
- Dim xlApp As Object
- Dim xlWb As Object
- Dim xlWs As Object
- Dim intRow As Integer
- Dim Rows As Object
- Dim xlUp As Object
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BStart.Click
- If CAuswahl.Text = "Exportieren" Then
- 'Outlook-Objekte öffnen
- olApp = CreateObject("Outlook.Application")
- olNameSpace = olApp.GetNamespace("MAPI")
- olContactsFolder = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts)
- olAll = olContactsFolder.Items
- 'Verteilerlisten herausfiltern,
- 'nur 'Richtige Kontakte' verwenden
- strContactFilter = "[MessageClass] = 'IPM.Contact'"
- olReal = olAll.Restrict(strContactFilter)
- 'Excel-Objekte öffnen
- xlApp = CreateObject("Excel.Application") 'Neue Excel-Instanz
- xlWb = xlApp.Workbooks.Add 'Neues Workbook anlegen
- xlWs = xlWb.Sheets(1) 'Erstes Sheet
- 'Excel-Worksheet aufbereiten
- With xlWs
- 'Sheet-Name
- .Name = "Outlook-Kontakte"
- 'Spaltenüberschriften
- .cells(1, 1).Value = "Vorname"
- .cells(1, 2).Value = "Nachname"
- .cells(1, 3).Value = "E-Mail"
- .cells(1, 4).Value = "Strasse"
- .cells(1, 5).Value = "PLZ"
- .cells(1, 6).Value = "Ort"
- .cells(1, 7).Value = "Land"
- .cells(1, 8).Value = "Telefon"
- 'Spaltenüberschriften fett
- .Rows("1:1").Font.Bold = True
- 'Outlook-Kontakte nach Excel übertragen
- intRow = 2
- For Each itmContacts In olReal
- .cells(intRow, 1).Value = itmContacts.FirstName
- .cells(intRow, 2).Value = itmContacts.LastName
- .cells(intRow, 3).Value = itmContacts.Email1Address
- .cells(intRow, 4).Value = itmContacts.BusinessAddressStreet
- .cells(intRow, 5).Value = itmContacts.BusinessAddressPostalCode
- .cells(intRow, 6).Value = itmContacts.BusinessAddressCity
- .cells(intRow, 7).Value = itmContacts.BusinessAddressCountry
- .cells(intRow, 8).Value = itmContacts.BusinessTelephoneNumber
- intRow = intRow + 1
- Next itmContacts
- 'Optimale Spaltenbreite
- .Columns.AutoFit()
- syncSuccess = True
- CreateContacts_Exit:
- If syncSuccess = True Then
- MsgBox("Die Synchronisierung war erfolgreich", vbInformation)
- Me.Close()
- Else
- MsgBox("Die Synchronisierung ist fehlgeschlagen", vbInformation)
- End If
- End With
- 'Excel einblenden
- xlApp.Visible = True
- xlWb.SaveAs("C:\Kontakte\Kontakte " & DateString & ".xlsx")
- For Each Process In System.Diagnostics.Process.GetProcessesByName("excel")
- Process.Kill()
- Next
- 'Speicher freigeben
- olReal = Nothing
- olAll = Nothing
- olContactsFolder = Nothing
- olNameSpace = Nothing
- xlWs = Nothing
- xlWb = Nothing
- xlApp = Nothing
- ElseIf CAuswahl.Text = "Importieren" Then
- Dim olApp As Microsoft.Office.Interop.Outlook.Application
- Dim olNameSpace As Microsoft.Office.Interop.Outlook.NameSpace
- Dim olContactsFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
- Dim olAll As Microsoft.Office.Interop.Outlook.Items
- Dim olReal As Microsoft.Office.Interop.Outlook.Items
- Dim olContact As Microsoft.Office.Interop.Outlook.ContactItem
- Dim AllProcesses() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses()
- Dim MyProcess As System.Diagnostics.Process
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim exWb As Microsoft.Office.Interop.Excel.Workbook
- Dim exWs As Microsoft.Office.Interop.Excel.Worksheet
- Dim intRow As Integer
- Dim lngLastRow As Long
- Dim lngContactsCount As Long
- Dim syncSuccess As Boolean
- Dim strContactFilter As String
- Dim aktzeile As Integer
- Dim zeilennr As Integer
- Dim inhalt As Object
- Dim FileName As String
- Dim ToRangeCounter As Object
- Dim xlUp As Long
- Dim xlToRight As Long
- Dim Contact As Object
- xlApp = CreateObject("Excel.Application")
- olApp = CreateObject("Outlook.Application")
- olNameSpace = olApp.GetNamespace("MAPI")
- olContactsFolder = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts)
- With xlApp
- xlApp.Visible = True
- xlWb = xlApp.Workbooks.Open("C:\Kontakte\Kontakte " & DateString & ".xlsx")
- End With
- olContact = olApp.CreateItem(Outlook.OlItemType.olDistributionListItem)
- intRow = 0
- For Each itmContacts In olReal
- itmContacts.FirstName = xlWs.cells(intRow, 1).Value
- itmContacts.LastName = xlWs.cells(intRow, 2).Value
- itmContacts.Email1Address = xlWs.cells(intRow, 3).Value
- itmContacts.BusinessAddressStreet = xlWs.cells(intRow, 4).Value
- itmContacts.BusinessAddressPostalCode = xlWs.cells(intRow, 5).Value
- itmContacts.BusinessAddressCity = xlWs.cells(intRow, 6).Value
- itmContacts.BusinessAddressCountry = xlWs.cells(intRow, 7).Value
- itmContacts.BusinessTelephoneNumber = xlWs.cells(intRow, 8).Value
- intRow = intRow + 1
- itmContacts.Save()
- Next
- ' .ActiveWorkbook.Save
- ' .ActiveWorkbook.Close
- ' .Quit
- End If
- End Sub
- Private Sub BExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BExit.Click
- Me.Close()
- End Sub
- End Class
*Topic verschoben, das ist kein VBScript*
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()