本帖最后由 ArdentMan 于 2011-7-11 08:36 编辑
- Dim Path, FSO, EXCEL, Book, Arr, Str
- Path = CreateObject("Wscript.Shell").CurrentDirectory & "\"
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Str = FSO.OpenTextFile("a.txt").ReadAll()
- Arr = Split(Str, vbCrLf)
- Set FSO = Nothing
- Set EXCEL = CreateObject("Excel.Application")
- EXCEL.Visible = False
- Set Book = EXCEL.Workbooks.Open(Path & "b.xls")
- For Each Str In Arr
- If Str <> "" Then
- i = i + 1
- EXCEL.Cells(i, 2).value = Split(Str, ";")(3)
- End If
- Next
- Book.Save
- Book.Close
- Set Book = Nothing
- EXCEL.Quit
- Set EXCEL = Nothing
- MsgBox "导入完成!", , "ArdentMan友情提示"
复制代码 注:
楼主的文本式样中的分隔符是全角的分号,是不是搞错了,如果搞错了请将代码Split(Str, ";")(3)中的全角分号改为半角分号,b.excel应该为b.xls,代码保存为test.vbs到a.txt和b.xls所在目录中双击运行,有问题请及时反馈~~~ |