7,763
社区成员
发帖
与我相关
我的任务
分享
Dim ex As Object
Dim wb As Object
Dim sh As Object
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim fn As Long, strT As String, arr() As String
For i = 0 To File1.ListCount - 1
fn = FreeFile
Open Replace(File1.Path & "\" & File1.List(i),"\\","\") For Input As #fn
For j = 1 To 3
Line Input #fn, strT
Next j
Close #fn
arr = Split(strT, ",")
sh.Cells(i + 1, 1) = arr(0)
sh.Cells(i + 1, 2) = arr(1)
sh.Cells(i + 1, 3) = arr(4)
sh.Cells(i + 1, 4) = arr(6)
sh.Cells(i + 1, 5) = arr(7)
Next i
ex.Visible = True
End Sub
Private Sub Form_Load()
File1.Pattern = "*.txt"
File1.Path = ....这里是你的txt文件的路径,如 c:\
Set ex = CreateObject("Excel.Application")
Set wb = ex.workbooks.Add
Set sh = wb.Sheets(1)
End Sub
Dim ex As Object
Dim wb As Object
Dim sh As Worksheet
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim fn As Long, strT As String, arr() As String
For i = 0 To File1.ListCount - 1
fn = FreeFile
Open Replace(File1.Path & "\" & File1.List(i),"\\","\") For Input As #fn
For j = 1 To 3
Line Input #fn, strT
Next j
Close #fn
arr = Split(strT, ",")
sh.Cells(i + 1, 1) = arr(0)
sh.Cells(i + 1, 2) = arr(1)
sh.Cells(i + 1, 3) = arr(4)
sh.Cells(i + 1, 4) = arr(6)
sh.Cells(i + 1, 5) = arr(7)
Next i
ex.Visible = True
End Sub
Private Sub Form_Load()
File1.Pattern = "*.txt"
File1.Path = ....这里是你的txt文件的路径,如 c:\
Set ex = CreateObject("Excel.Application")
Set wb = ex.workbooks.Add
Set sh = wb.Sheets(1)
End Sub
Option Explicit
Private Sub getvalue(ByVal filename As String, ByRef value() As String)
Dim s As String
Dim ss() As String
Dim linecount As Long
Dim i As Long
Open filename For Input As #1
Do
Line Input #1, s
linecount = linecount + 1
If 3 = linecount Then
ss = Split(s, ",")
For i = 0 To UBound(ss) - 1
value(i + 1) = ss(i)
Next i
Close #1
Exit Sub
End If
Loop While Not EOF(1)
Close #1
End Sub
Private Sub Command1_Click()
Dim a(1 To 100) As String
getvalue "d:\000.txt", a
Debug.Print a(1)
Debug.Print a(2)
Debug.Print a(5)
Debug.Print a(7)
Debug.Print a(8)
End Sub