用vba把txt文档里的资料放入excel表格里
我的txt信息是这样的,文档里有【名称】数据,【电话】数据,【邮箱】数据等8个类似数据,想把这些信息放入excel表格中,用vba该这么编程啊,请高手帮忙~谢谢...
我的txt信息是这样的,文档里有【名称】数据,【电话】数据,【邮箱】数据等8个类似数据,想把这些信息放入excel表格中,用vba该这么编程啊,请高手帮忙~谢谢
展开
3个回答
展开全部
把文件路径换成实际的
Sub ReadTxt()
A = Array("【企业名称】", "【负责人】", "职务", "【地址】", "【电话】", "【传真】", "【网址】", "【E - mail】")
Open "C:\Documents and Settings\Administrator\桌面\58.TXT" For Input As #1
R = 1
Range(Cells(1, 1), Cells(1, 8)) = A
While Not EOF(1)
Line Input #1, S
If InStr(S, "【企业名称】") > 0 Then
R = R + 1
Cells(R, 1) = Trim(Replace(S, "【企业名称】", ""))
End If
If InStr(S, "【负责人】") > 0 Then
L = InStr(S, "职务")
If L > 0 Then
Cells(R, 2) = Replace(Left(S, L - 1), "【负责人】", "")
Cells(R, 3) = Replace(Right(S, Len(S) - L - 2), "职务:", "")
Else
Cells(R, 2) = Trim(Replace(S, "【负责人】", ""))
End If
End If
For i = 3 To 7
If InStr(S, A(i)) > 0 Then Cells(R, i + 1) = Replace(S, A(i), "")
Next
Wend
Close 1
End Sub
Sub ReadTxt()
A = Array("【企业名称】", "【负责人】", "职务", "【地址】", "【电话】", "【传真】", "【网址】", "【E - mail】")
Open "C:\Documents and Settings\Administrator\桌面\58.TXT" For Input As #1
R = 1
Range(Cells(1, 1), Cells(1, 8)) = A
While Not EOF(1)
Line Input #1, S
If InStr(S, "【企业名称】") > 0 Then
R = R + 1
Cells(R, 1) = Trim(Replace(S, "【企业名称】", ""))
End If
If InStr(S, "【负责人】") > 0 Then
L = InStr(S, "职务")
If L > 0 Then
Cells(R, 2) = Replace(Left(S, L - 1), "【负责人】", "")
Cells(R, 3) = Replace(Right(S, Len(S) - L - 2), "职务:", "")
Else
Cells(R, 2) = Trim(Replace(S, "【负责人】", ""))
End If
End If
For i = 3 To 7
If InStr(S, A(i)) > 0 Then Cells(R, i + 1) = Replace(S, A(i), "")
Next
Wend
Close 1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询