ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¥N½X¤ÀªR¨D§U

[µo°Ý] ¥N½X¤ÀªR¨D§U

sample.rar (18.17 KB)



¯à§_½Ð¦U¦ì¥ý¶iÀ°¦£VB¤@¤U

1.¶×¤J¬Y«ü©w¸ê®Æ§¨©Ò¦³*.txt ÀÉ®×

2.¦b·s¤À­¶¬éÅã¥Ü«eºó¦³¼Æ¦r¥N½X¤§¦r¦ê¡A¤£Åã¥ÜµL¼Æ¦r¥N½X¦r¦ê(¦p¬õ¦âmark©Ò¥Ü)

3.±N¦³¼Æ¦r¥N½X¤U¦æª¬ªp¦r¦ê²¾¨ì «e¦C¥N½X¤§«á

4.±N¦r¦ê¤À³Î¬°¤£¦PÄæ¦ì ¦p¼Æ¦r¦r¦ê¬°A1 ¤é´Á¦r¦ê¬° B1 ®É¶¡¦r¦ê¬° C1

¦b·s¤â­±«e·Pı¦³ÂI§xÃø¡A±æ°ª¤â¯àÀ°¦£ ·P¿E¤£ºÉ

¦^´_ 1# mrkacs
  1. Sub Example()
  2.     Dim sPath As String
  3.     With Application.FileDialog(msoFileDialogFolderPicker)
  4.         .Title = "½Ð¿ï¾Ü¸ê®Æ§¨"
  5.         If .Show = -1 Then
  6.             If .SelectedItems.Count > 0 Then sPath = .SelectedItems(1) Else Exit Sub
  7.         End If
  8.     End With
  9.    
  10.     Dim oReg As Object: Set oReg = CreateObject("vbscript.regexp")
  11.     With oReg
  12.         .MultiLine = True
  13.         .Global = True
  14.         .Pattern = "^\s*(\S{1,10}) (\d{2})/(\d{2})/(\d{4}) (\d{2}:\d{2}:\d{2}) (.{15}) (.{10}) (.{10}) (.{6})\s*\r\n(.*)\r\n"
  15.     End With
  16.    
  17.     Dim ws As Worksheet
  18.     Set ws = Workbooks.Add.Sheets(1)
  19.    
  20.     Const ForReading = 1
  21.     Dim oFSO As Object: Set oFSO = CreateObject("Scripting.FileSystemObject")
  22.     Dim oTF, oFD, sText
  23.     Dim curRow As Long
  24.     Dim match
  25.     Set oFD = oFSO.getfolder(sPath)
  26.     For Each f In oFD.Files
  27.         If oFSO.getextensionname(f.Path) = "txt" Then
  28.             Set oTF = oFSO.OpenTextFile(f.Path, ForReading)
  29.             sText = oTF.ReadAll
  30.             Set match = oReg.Execute(sText)
  31.             With ws
  32.                 For Each it In match
  33.                     curRow = curRow + 1
  34.                     .Cells(curRow, 1) = Trim(it.submatches(0))
  35.                     .Cells(curRow, 2) = DateSerial(it.submatches(3), it.submatches(2), it.submatches(1))
  36.                     .Cells(curRow, 3) = CDate(it.submatches(4))
  37.                     .Cells(curRow, 4) = Trim(it.submatches(5))
  38.                     .Cells(curRow, 5) = Trim(it.submatches(6))
  39.                     .Cells(curRow, 6) = Trim(it.submatches(7))
  40.                     .Cells(curRow, 7) = Trim(it.submatches(8))
  41.                     .Cells(curRow, 8) = Trim(it.submatches(9))
  42.                 Next
  43.             End With
  44.         End If
  45.     Next
  46.     With ws
  47.         .[B:B].NumberFormatLocal = "dd/mm/yyyy"
  48.         .[C:C].NumberFormatLocal = "hh:mm:ss"
  49.         .UsedRange.EntireColumn.AutoFit
  50.     End With
  51.     MsgBox "Finish"
  52. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 2# stillfish00


«D±`·PÁ stillfish00  ªºÀ°¦£

¦ý¦b³o¥ý¹D­Óºp §Ú¤W¶ÇªºÀɮ׮榡¦³ÂI»~®t

«á¨Ó³o¥÷ÀɮקڹÁ¸Õ­×§ï¤º®e ¦ý¬O°õ¦æµ{¦¡½X±o¤£¨ì¥ô¦ó¸ê®Æ

¯à½Ð±z¦AÀ°¦£­×§ï¤@¤U¶Ü?

ªþ¥ó¦p¤U

999.rar (2.25 KB)

TOP

¦^´_ 3# mrkacs
  1. Sub Example()
  2.     Dim sPath As String
  3.     With Application.FileDialog(msoFileDialogFolderPicker)
  4.         .Title = "½Ð¿ï¾Ü¸ê®Æ§¨"
  5.         If .Show = -1 Then
  6.             If .SelectedItems.Count > 0 Then sPath = .SelectedItems(1) Else Exit Sub
  7.         End If
  8.     End With
  9.    
  10.     Dim oReg As Object: Set oReg = CreateObject("vbscript.regexp")
  11.     With oReg
  12.         .MultiLine = True
  13.         .Global = True
  14.         .Pattern = "^\s*(\S{1,10}) (\d{2})/(\d{2})/(\d{4}) (\d{2}:\d{2}:\d{2}) (.{15}) (.{10}) (.{10}) (.{7}) (.{13}) (.{12}) (.{11}) (.*)\r\n(.*)\r\n"
  15.     End With
  16.    
  17.     Dim ws As Worksheet
  18.     Set ws = Workbooks.Add.Sheets(1)
  19.    
  20.     Const ForReading = 1
  21.     Dim oFSO As Object: Set oFSO = CreateObject("Scripting.FileSystemObject")
  22.     Dim oTF, oFD, sText
  23.     Dim curRow As Long
  24.     Dim match
  25.     Set oFD = oFSO.getfolder(sPath)
  26.     For Each f In oFD.Files
  27.         If oFSO.getextensionname(f.Path) = "csv" Then
  28.             Set oTF = oFSO.OpenTextFile(f.Path, ForReading)
  29.             sText = oTF.ReadAll
  30.             Set match = oReg.Execute(sText)
  31.             With ws
  32.                 For Each it In match
  33.                     curRow = curRow + 1
  34.                     .Cells(curRow, 1) = Trim(it.submatches(0))
  35.                     .Cells(curRow, 2) = DateSerial(it.submatches(3), it.submatches(2), it.submatches(1))
  36.                     .Cells(curRow, 3) = CDate(it.submatches(4))
  37.                     For j = 4 To 7
  38.                         .Cells(curRow, j) = Trim(it.submatches(j + 1))
  39.                     Next
  40.                     .Cells(curRow, 8) = CDate(it.submatches(9))
  41.                     .Cells(curRow, 9) = CDate(it.submatches(10))
  42.                     .Cells(curRow, 10) = CDate(it.submatches(11))
  43.                     .Cells(curRow, 11) = Trim(it.submatches(12))
  44.                     .Cells(curRow, 12) = Trim(it.submatches(13))
  45.                 Next
  46.             End With
  47.         End If
  48.     Next
  49.     With ws
  50.         .[B:B].NumberFormatLocal = "dd/mm/yyyy"
  51.         .[C:C,H:J].NumberFormatLocal = "hh:mm:ss"
  52.         .UsedRange.EntireColumn.AutoFit
  53.     End With
  54.     MsgBox "Finish"
  55. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 4# stillfish00


    «D±`·PÁ±zªºÀ°¦£¡Aµ{¦¡°õ¦æªº«Ü¶¶§Q

TOP

        ÀR«ä¦Û¦b : ¤Hªº²´·úªø¦b«e­±¡A¥u¬Ý¨ì§O¤Hªº¯ÊÂI¡Aµ·²@¬Ý¤£¨ì¦Û¤vªº¯ÊÂI¡C
ªð¦^¦Cªí ¤W¤@¥DÃD