§Ú¦³¤@¥÷©T©w²£¥Xªº¤å¥óÀÉ
®æ¦¡¦p¤U,Àɮפwªþ¤W
(ºØÃþ·|¦³¼Æ¤QºØ,»Ý¨ú¨ä¤¤¤@ºØ«ü©wºØÃþ¨ÃÓ§O²Îp¶µ¥Ø¼Æ¶q)
¦³§ä¨ì¨â¥÷¦³ÂIÃþ¦üªºµ{¦¡½X¦ý§ï¤£¦n- Sub ReadfiletoExcel()
- Dim s As Worksheet
- Dim f As Integer
- Dim r As String
- Dim i As Integer
- Dim j As Integer
- Dim a() As String
- i = 2 '±q²Äi¦C¶}©l¼g¤JÀɮ׸ê®Æ,i¥i¦Ûq¨Ì¦Û¤v»Ýn,¦b³o½d¨Ò³]i¬°5
- Set s = ActiveSheet
- f = FreeFile
- Open s.Range("A1").Value For Input As #f
- Do While Not EOF(f)
- Line Input #f, r
- a = Split(r, ",") '¸ÓÀÉ®×¥H,¬°¤À¹j²Å¸¹
- For j = 0 To UBound(a)
- s.Cells(i, j + 1).Value = a(j) 'Ū¨ú¸ê®Æ¨Ì§Ç¦s¤J²Äi¦Cªº²Ä1Ó¨ìjÓÄæ¦ì
- Next j
- i = i + 1
- Loop
- Close #f
- MsgBox "Ū¨úÀɮ׸ê®Æok"
- End Sub
½Æ»s¥N½X- Function PutRowData(strData As String, strSheets As String, strCol As String)
- '¶ë¸ê®Æ¨ì«ü©wÄæ¦ì¡A¨Ã©ñ¨ì¸ÓÄ檺³Ì«áªÅ¥Õ¦C
- '¸ê®Æ¦ê¥ÑTab¦r¤¸¦Û°Ê¤Á¶}¡A©ñ¸m¤£¦PÄ檺¸ê®Æ¨ì¤£¦PÄæ¦ì¸Ì
- '
- 'strData ¸ê®Æ¦ê
- 'strSheets «ü©w¤u§@ªí
- 'strCol «ü©wÄæ¦ì¡]^¤å¦r¡^
- Dim objDes As Object
- Set objDes = Sheets(strSheets)
- iNewRow = objDes.Range(strCol & "65535").End(xlUp).Row + 1
- If iNewRow = 2 Then
- objDes.Columns("A:B").ColumnWidth = 23
- objDes.Columns("C").ColumnWidth = 8
- objDes.Columns("D").ColumnWidth = 29
- objDes.Columns("E:P").ColumnWidth = 8
- objDes.Columns("Q").ColumnWidth = 29
- 'objDes.Columns("A:Q").EntireColumn.AutoFit
- Title = "ºØÃþ"
- tmpTitle = Split(Title, ",")
- For intI = 0 To UBound(tmpTitle)
- intC = intI + 1
- objDes.Range(strCol & "2").Offset(0, intC) = tmpTitle(intI)
- Next
- iNewRow = iNewRow + 3
- End If
- tmp = Split(strData, ",")
- For i = 0 To UBound(tmp)
- If i = 16 Then '²Ä16Ó°}¦CȨú26Ó¦r¤¸ = 00 00 00 00 00 00 00 00 00 00
- objDes.Range(strCol & iNewRow).Offset(0, i) = Mid(tmp(i), 1, 29)
- Else
- objDes.Range(strCol & iNewRow).Offset(0, i) = tmp(i)
- End If
- Next
- End Function
- Public Function ReadATextFileToEOF(strKeyWord As String, Optional strPath As String, Optional strFileType As String = "*.*")
- 'Åýuser¿ï¾Ü¯Â¤å¦rÀÉ¡A¥´¶}Àɮ׫á¡A³v¦æ·j´M¡A§ä¨ìÃöÁä¦r¡A´N§â¸ê®Æ©ñ¨ì²{¦bªº¤u§@ªí¤º
- 'Åܼƻ¡©ú
- 'strKeyWord ÃöÁä¦r
- 'strPath ¹w³]¶}±Ò¸ô®|
- 'strFileType ÀÉ®×Ãþ«¬ *.txt ©Î¨ä¥L
- '
- Dim intFile As Integer
- Dim strFile As String
- Dim strIn As String
- Dim bnFound As Boolean
- booFound = False
- strOut = vbNullString
- intFile = FreeFile()
- Range("A1:IV65536").ClearContents '²M°£ªí®æ¸ê®Æ
- Dim fd As FileDialog, FileName As String, FileFolder As String
- Set fd = Application.FileDialog(3)
- With fd
- .Filters.Clear
- .Filters.Add "All Text Files", "*.txt"
- .AllowMultiSelect = False
- If .Show = -1 Then
- strFile = .SelectedItems(1) '#1
- Else
- End
- End If
- End With
- MsgBox "±zªºÀɮ׸ô®|¦p¤U" & vbCrLf & strFile
- 'strFile = "d:\1231.txt"
- '¨Ï¥ÎOpen¤è¦¡¶}±Ò¯Â¤å¦rÀÉ(¤£¤ä´©UTF8)
- Open strFile For Input As #intFile
- i = 0
- Do While Not EOF(intFile)
- Line Input #intFile, strIn '¨Ì·Ó¡u¦æ¡v¨ÓŪ¨ú¸ê®Æ
- i = i + 1
- j = InStr(strIn, strKeyWord) '¨Ï¥ÎInStr¦r¦ê·j´M¡A¦³§ä¨ìÃöÁä¦r¡A´N±a¤J¨ì¤u§@ªí¤¤
- If j > 0 Then
- 'Call PutRowData("¡u" & strKeyWord & "¡v¦b²Ä " & i & "¦æ¡A²Ä " & j & "¦r¤¸," & Mid(strIn, j, 170), ActiveSheet.Name, "B")
- Call PutRowData(Mid(strIn, j, 170), ActiveSheet.Name, "A")
- 'MsgBox (strIn)
- bnFound = True
- End If
- Loop
- Close #intFile
- If bnFound = False Then
- MsgBox "§ä¤£¨ìÃöÁä¦r¡I"
- End If
- End Function
- Sub «ö¶s2_Click()
- Call ReadATextFileToEOF("ºØÃþ:¦×«~", "", "*.txt")
- End Sub
½Æ»s¥N½X ºØÃþ: ¦×«~
¸H½Þ¦×
--------
²£«~³W®æ: 5/20
--------
XXXXXXXXX-³Æµù
--------
XXXXXXXXX-ª`·N¨Æ¶µ
ºØÃþ: ¦A»s«~
°^¤Y
--------
²£«~³W®æ: 8/20
--------
XXXXXXXXX-³Æµù
--------
XXXXXXXXX-ª`·N¨Æ¶µ
ºØÃþ: ³½Ãþ
ÂD³½
--------
²£«~³W®æ: 8/20
--------
XXXXXXXXX-³Æµù
--------
XXXXXXXXX-ª`·N¨Æ¶µ
ºØÃþ: ¦×«~
½Þ¦×¤ù
--------
²£«~³W®æ: 80/120
--------
XXXXXXXXX-³Æµù
--------
XXXXXXXXX-ª`·N¨Æ¶µ
ì©lÀÉ®×:
CH.rar (210 Bytes)
§e²{µ²ªG:
§e²{µ²ªG.rar (6.65 KB)
|