如何阅读在VBA中读取文本文件 [英] how to read Read text file in VBA
本文介绍了如何阅读在VBA中读取文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格中包含一些值(键)和一个文本文件,大小为80 MB。我想从excel文件中读取密钥并在文本文件中搜索。此外,我想从该文本文件中提取该密钥的信息。我怎样才能做到这一点?
解决方案
既然你没有说什么是在文本文件或如何它涉及到工作表,什么键是的,它有点空中,但也许以下将让你开始
Sub GetValueFromTextFile()
Dim iNum As Integer
Dim strLine As String
Dim oRng As Range:Set oRng = Range(" A1")
iNum = FreeFile()
打开" c:\ Path \\ \\Filename.txt"对于输入为#iNum
Do While EOF(iNum)
行输入#iNum,strLine
如果InStr(1,strLine,oRng.Text)> 0然后
'用找到的行做一些事情,例如其写入到B1'
oRng.Offset(0,1)= strLine中
退出执行
结束如果
环
关闭#iNum
lbl_Exit:
Set oRng = Nothing
退出Sub
End Sub
I've excel sheet with some values(key) and one text file which is huge 80 MB. I want read key from excel file and search in text file. Further I wan to extract information from that text file for that key. How can I do that?
解决方案
Given that you haven't said what is in the text file or how it relates to the worksheet and what the keys are, it's all a bit up in the air, but maybe the following will get you started
Sub GetValueFromTextFile() Dim iNum As Integer Dim strLine As String Dim oRng As Range: Set oRng = Range("A1") iNum = FreeFile() Open "c:\Path\Filename.txt" For Input As #iNum Do While Not EOF(iNum) Line Input #iNum, strLine If InStr(1, strLine, oRng.Text) > 0 Then 'Do something with the found line e.g. write it to B1' oRng.Offset(0, 1) = strLine Exit Do End If Loop Close #iNum lbl_Exit: Set oRng = Nothing Exit Sub End Sub
这篇关于如何阅读在VBA中读取文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文