把一个文件夹下面所有txt文件导入notes

来源:互联网 发布:测试电脑显卡的软件 编辑:程序博客网 时间:2024/05/17 01:32

Sub Click(Source As Button)
 On Error Goto UnknowError
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim pathName As String, fileName As String
 Dim fileNum As Integer
 Dim stream As NotesStream
 
 Set db=session.CurrentDatabase
 Set stream = session.CreateStream
 directory$ = "D:/Test"
 Chdir directory$
 fileName$ = Dir$("*.*")
 Do While fileName$ <> ""
  pathName="D:/Test/" & fileName
  If Not stream.Open(pathName) Then
   Messagebox fileName$,, "Open failed"
   Exit Sub
  End If
  Set doc = New NotesDocument(db)
  doc.Form = "TxtContent"
  doc.Txt = stream.ReadText()
  Call doc.Save(True,False)
  Call stream.Close
  fileNum=fileNum+1
  fileName$ = Dir$()
 Loop
 Msgbox "共导入" & fileNum & "个文件"
 Exit Sub
UnknowError:
 Msgbox "错误行:" & Erl & "错误信息:" & Error
 Exit Sub
End Sub

原创粉丝点击