|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub ImportProjectCSVToOutlook()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objContacts As MAPIFolder
Dim objContact As Outlook.ContactItem
Dim fso As Scripting.FileSystemObject
Dim objStream As Scripting.TextStream
Dim strFileName As String
Dim strLine As String
Dim arr() As String
strFileName = _
InputBox("File to import:", "Import to Outlook")
If strFileName <> "" Then
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strFileName) Then
Set objStream = fso.OpenTextFile(strFileName, ForReading)
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
Do Until objStream.AtEndOfStream
strLine = objStream.ReadLine
arr = Split(strLine, ",")
Set objItem = objContacts.Items.add("IPM.Contact.Project")
With objItem
.FullName = arr(0)
.UserProperties("Project") = arr(1)
.Save
End With
Loop
objStream.Close
End If
End If
Set objNS = Nothing
Set objContacts = Nothing
Set objContact = Nothing
Set objApp = Nothing
Set objStream = Nothing
Set fso = Nothing
End Sub |
|