请教高手如何用vbs把txt的数据写到已有excel的指定单元格

2024-12-03 16:44:47
推荐回答(2个)
回答(1):

set fso=createobject("scripting.filesystemobject")
set ex=createobject("excel.application")
ex.visible=true
ex.workbooks.open path1
'path1是你的1.xls表格路径
set f=fso.opentextfile(path2,1)
'path2是你的1.txt的路径
str=f.readline
f.close
a=split(str," ")
ex.cells(1,1).value=a(4)
ex.ActiveWorkbook.Save
ex.quit

回答(2):

假设1.txt保存在C:\,(每个数据占一行)
建一个按钮控件
Private Sub CommandButton1_Click()
Dim t(6) As Integer
Open "c:\1.txt" For Input As #1
k = 1
Do While Not EOF(1)
Line Input #1, textline
t(k) = textline
k = k + 1
Loop
Close #1
Cells(5, 1) = t(5)
End Sub