2015-01-13 2 views
0

연락처 목록을 반복하는 것으로 보이는이 코드가 있지만 Outlook 연락처를 만들지 못하거나 오류가 발생하지 않습니다. 어떤 아이디어?VB.net CSV 파일에서 연락처 만들기

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click 
    Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser("c:\contacts.csv") 
    Dim CurrentRecord As String() ' this array will hold each line of data 
    afile.TextFieldType = FileIO.FieldType.Delimited 
    afile.Delimiters = New String() {vbTab} 
    afile.HasFieldsEnclosedInQuotes = True 


    Dim oApp As Outlook.Application 
    oApp = CreateObject("Outlook.Application") 

    Dim oNs As Outlook.NameSpace 
    oNs = oApp.GetNamespace("MAPI") 
    oNs.Logon() 

    Dim oItem As Outlook.ContactItem 
    oItem = oApp.CreateItem(OlItemType.olContactItem) 

    ' parse the actual file 
    Do While Not afile.EndOfData 
     Try 
      CurrentRecord = afile.ReadFields 

      With oItem 
       .FirstName = CurrentRecord(0) 
       .LastName = CurrentRecord(1) 
       End With 

      oItem.Save() 
     Catch ex As FileIO.MalformedLineException 
      Stop 
     End Try 
    Loop 
    MsgBox("Complete") 
End Sub 

가장 좋은 방법인지 확실하지 않으므로 제안 사항에 대해 답변드립니다. (그래, 난을 통해 "뿐만 동안 수행" "까지 수행"선호)이 전체 문제의 경우

답변

0

은 몰라,하지만 당신은 루프 내부의 각 연락처를 작성해야합니다

Do Until afile.EndOfData 
    Try 
     CurrentRecord = afile.ReadFields 
     oItem = oApp.CreateItem(OlItemType.olContactItem) 
     With oItem 
      .FirstName = CurrentRecord(0) 
      .LastName = CurrentRecord(1) 
      .Save() 
     End With    
    Catch ex As FileIO.MalformedLineException 
     Stop 
    End Try 
Loop 
관련 문제