excel用vba自动提取指定txt文件中指定位置字符到excel指定单元格中
1个回答
展开全部
我刚刚编辑的,请试用。如下代码可实现提取第四行第四列的数据。
Sub xxx()
Dim myFile As String
Dim myText As String
Dim myString As String
Dim i As Single
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
.AllowMultiSelect = False
myFile = .SelectedItems(1)
End With
myText = Dir(myFile & "\" & "*.txt")
Do While Len(myText) <> 0
Open myFile & "\" & myText For Input As #1
myText = Split(Split(VBA.StrConv(InputB(LOF(1), 1), vbUnicode), Chr(10))(3), vbTab)(3) '4行4列,如果其余行或列数则更改相应的数字
Debug.Print myText
Close
myText = Dir
Loop
End Sub
Sub xxx()
Dim myFile As String
Dim myText As String
Dim myString As String
Dim i As Single
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
.AllowMultiSelect = False
myFile = .SelectedItems(1)
End With
myText = Dir(myFile & "\" & "*.txt")
Do While Len(myText) <> 0
Open myFile & "\" & myText For Input As #1
myText = Split(Split(VBA.StrConv(InputB(LOF(1), 1), vbUnicode), Chr(10))(3), vbTab)(3) '4行4列,如果其余行或列数则更改相应的数字
Debug.Print myText
Close
myText = Dir
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询