菜单里选择[工程] -- [引用],添加 Microsoft Excel XX.X Object Library的引用
Private Sub Command1_Click()
Dim xlapp As Excel.Application '定义excel类
Dim xlbook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类
Dim filepath As String
filepath = App.Path & "\123.xls"
Set xlapp = CreateObject("excel.application") '创建excel应用类
xlapp.Visible = False '设置excel不可见
Set xlbook = xlapp.Workbooks.Open(filepath) '打开excel工作簿
Set xlsheet = xlbook.Worksheets(1) '打开excel工作表
Text1.Text = xlsheet.Cells(Val(Text2.Text), 3)
Set xlsheet = Nothing
Set xlbook = Nothing
xlapp.Quit
Set xlapp = Nothing
End Sub
Private Sub Command2_Click()
Dim filepath As String
Dim s As String
Dim counts As Integer
Dim HangShu As Integer
HangShu = Val(Text2.Text) '行数
filepath = App.Path & "\123.txt" '文本文档名称为 123.txt
Open filepath For Input As #1
Do Until EOF(1)
Input #1, s
counts = counts + 1
If counts = HangShu Then
counts = 0
Text1.Text = Split(s, " ")(2) '读取第三列
Exit Do
End If
Loop
Close #1
End Sub
追问要一个一个的取,而且这个文件在取的时候还有其他程序往里写数据。这能实现吗?俺是菜鸟,望大虾指教
(我要做的是通过数据采集卡采到的数据保存到excel或txt中。在采集的过程中,要用这些采到的数据做计算,所以想把他取出来,)
追答能实现啊,你想取哪个取哪个,程序只需要把里面的数改改就好了!
本回答被提问者采纳