zhujie-com

Dim r%
Sub ImportFromTextFile()
Dim fso As Object, sFile As Object, blnExist As Boolean
Dim FileName As String, i As Integer, iCol As Integer, LineText As String
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject") \'创建FileSystemObject对象
FileName = "H:\nama_exi_p.tsv" \'指定文本文件名
blnExist = fso.FileExists(FileName) \'判断文件是否存在,如果不存在,则退出过程
If Not blnExist Then MsgBox "文件不存在!": Exit Sub
Set sFile = fso.OpenTextFile(FileName, ForReading) \'创建并打开名为sFile的TextStream对象
Do While Not sFile.AtEndOfStream \'如果不是文本文件的尾端,则读取数据
LineText = sFile.ReadLine
Call getNum1(LineText)
Loop
sFile.Close
Set fso = Nothing
Set sFile = Nothing
End Sub
Sub getNum1(str As String)
r = r + 1
Set reg = CreateObject("VBScript.RegExp")
With reg
.Global = True
.IgnoreCase = True
.Pattern = "(\S+)\s+(\S+)\s+(\S+)"
End With

Set mc = reg.Execute(str)
For Each m In mc

Cells(r, 1) = m.submatches.Item(0)
Cells(r, 2) = m.submatches.Item(1)
Cells(r, 3) = m.submatches.Item(2)
Next
End Sub

分类:

技术点:

相关文章:

  • 2021-12-23
  • 2021-10-17
  • 2021-04-10
  • 2021-12-14
  • 2021-10-17
  • 2021-07-30
  • 2021-11-20
  • 2021-10-03
猜你喜欢
  • 2021-10-08
  • 2021-12-26
  • 2021-05-24
  • 2021-10-28
  • 2021-11-29
  • 2021-12-23
  • 2021-12-03
相关资源
相似解决方案