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

[µo°Ý] ½Ð°Ý¦pªG¦³¤@­ÓªÑ²¼¸ê®Æ®w¡A¦p¦ó¨Ï¥Îvba¡K

¦^´_ 1# gkld
ActiveSheet  '§@¥Î¤¤ªº¤u§@ªí
¬O¬°¹Ï2 ¤¤ ³y¯ÈÃþ«ü¼Æ
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Ex_Path = "¸ê®Æ§¨¸ô®|\"                         '******­×§ï¥¦********
  5.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  6.     If Ex_File = "" Then
  7.         MsgBox "¨S¦³ A112*ALL_1.csv"
  8.         Exit Sub
  9.     End If
  10.     Application.ScreenUpdating = False
  11.     Do While Ex_File <> ""
  12.         Ex_Date = Replace(Ex_File, "A112", "")                     '®ø°£ÀɦW¤¤"A112"
  13.         Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '®ø°£ÀɦW¤¤"ALL_1.csv"
  14.         Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '±a¤J¤é´Á
  15.         With ActiveSheet                                            '§@¥Î¤¤ªº¤u§@ªí
  16.             Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò A11220070102ALL_1.csv.....
  17.             .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = Ex_Date  '¤é´Á¿é¤J
  18.             .Cells(.Rows.Count, "B").End(xlUp).Offset(1) = Ex_Wb.Sheets(1).Range("A:A").Find(.Range("B1"), lookat:=xlWhole).Offset(, 1)
  19.             '**** §@¥Î¤¤ªº¤u§@ªí.Range("B1") ¬°¬d¸ß«ü¼ÆªºÃþ§O  *********
  20.             Ex_Wb.Close                                             'Ãö³¬ A11220070102ALL_1.csv.....
  21.         End With
  22.         Ex_File = Dir                                               '¤U¤@­Ó"A112*ALL_1.csv"
  23.     Loop
  24.     Application.ScreenUpdating = True
  25.     MsgBox "OK"
  26. End Sub
½Æ»s¥N½X

TOP

¦^´_ 5# gkld
¥D­n¬O¬°¤F§ì¨ú¸ê®Æ®w¤¤¨C­Ócsvªºrange("b12")­È  
  1. .Cells(.Rows.Count, "B").End(xlUp).Offset(1) = Ex_Wb.Sheets(1).Range("B12")
½Æ»s¥N½X

TOP

¦^´_ 7# gkld
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range
  5.     Ex_Path = "¸ê®Æ§¨¸ô®|\"                         '******­×§ï¥¦********
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "¨S¦³ A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     Do While Ex_File <> ""
  13.         Ex_Date = Replace(Ex_File, "A112", "")                     '®ø°£ÀɦW¤¤"A112"
  14.         Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '®ø°£ÀɦW¤¤"ALL_1.csv"
  15.         Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '±a¤J¤é´Á
  16.         With ActiveSheet                                            '§@¥Î¤¤ªº¤u§@ªí
  17.             Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò A11220070102ALL_1.csv.....
  18.             '************************************************
  19.             .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = Ex_Date  '¤é´Á¿é¤J
  20.             If Ex_Wb.Sheets(1).Range("B12") <> "" Then
  21.                 .Cells(.Rows.Count, "B").End(xlUp).Offset(1) = Ex_Wb.Sheets(1).Range("B12")
  22.             Else
  23.                 .Cells(.Rows.Count, "B").End(xlUp).Offset(1) = "---"   '**¨S¦³¸ê®Æ
  24.                 '**** §@¥Î¤¤ªº¤u§@ªí.Range("B1") ¬°¬d¸ß«ü¼ÆªºÃþ§O  *********
  25.             End If
  26.             '************************************************
  27.             Ex_Wb.Close False                                       'Ãö³¬ A11220070102ALL_1.csv.....
  28.         End With
  29.         Ex_File = Dir                                               '¤U¤@­Ó"A112*ALL_1.csv"
  30.     Loop
  31.     Application.ScreenUpdating = True
  32.     MsgBox "OK"
  33. End Sub
½Æ»s¥N½X

TOP

¦^´_ 10# gkld
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  5.     Ex_Path = "C:\Documents and Settings\gkld\®à­±\my kp\¸ê®Æ®w\¤W¥«\"
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "¨S¦³ A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     'Ar = Array("¥xªd", "¨Èªd", "¹Åªd", "©¯ºÖ", "«H¤j", "ªFªd")
  13.     For i = 1 To 7
  14.        '** Name ¬OVBA©Ò¥ÎªºÃöÁä¦r¦ê,ÁקK¨Ï¥Î¬°ÅܼƦWºÙ.
  15.        ' If i = 1 Then Ex_Name = "¥xªd"
  16.        ' If i = 2 Then Ex_Name = "¨Èªd"
  17.        ' If i = 3 Then Ex_Name = "¹Åªd"
  18.        ' If i = 4 Then Ex_Name = "Àôªd"
  19.        ' If i = 5 Then Ex_Name = "©¯ºÖ"
  20.        ' If i = 6 Then Ex_Name = "«H¤j"
  21.        ' If i = 7 Then Ex_Name = "ªFªd"
  22.       
  23.         With Sheets(i)                                                '¨Ì¤u§@ªí¯Á¤Þ­È«ü©w¤u§@ªí
  24.         '****¤u§@ªí¦WºÙ ¦b¬¡­¶Ã¯µøµ¡±Æ§Ç¦p¬O¨ÌIF i=1¦p¦¹¶¶§Ç***
  25.         '***¨º´N¤£»Ý³o¨ÇIF i=1 ...........
  26.       
  27.         'With Sheets(Ex_Name)                                          '¨ÌEx_Name «ü©w¤u§@ªí
  28.         '****¦p¦b¬¡­¶Ã¯µøµ¡¤u§@ªí¦WºÙ±Æ§Ç¤£¬O¦p¦¹¶¶§Ç***
  29.         '***¨º´N»Ý­n³o¨ÇIF i=1 ...........
  30.       
  31.         'With Sheets(Ar(i - 1))                                      '«ü©w©w°}¦C¤¤ªº¤u§@ªí¦WºÙ
  32.             .Range("a1:ag65536").Clear '®ø°£¨C¤@¦æ¸ê®Æ
  33.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  34.             Do While Ex_File <> ""
  35.                 Ex_Date = Replace(Ex_File, "A112", "")                     '®ø°£ÀɦW¤¤"A112"
  36.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '®ø°£ÀɦW¤¤"ALL_1.csv"
  37.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '±a¤J¤é´Á
  38.                
  39.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò A11220070102ALL_1.csv.....
  40.                 '************************************************
  41.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '¨ú±o¸ê®Æ¿é¤Jªº¦C¸¹
  42.                 Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, lookat:=xlWhole)
  43.                  '.Cells(Ex_Row, "A") = Ex_Date  '¤é´Á¿é¤J         '** °O¿ý©Ò¦³¤é´Á***
  44.                 If Not Rng Is Nothing Then
  45.                     .Cells(Ex_Row, "A") = Ex_Date '¤é´Á¿é¤J  ¦p²¾¨ì³o¸Ì '** ¥u°O¿ý¦³¸ê®Æªº¤é´Á
  46.                     .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  47.                     .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  48.                     .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  49.                     .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  50.                     .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  51.                 End If
  52.                 '************************************************
  53.                 Ex_Wb.Close False                                       'Ãö³¬ A11220070102ALL_1.csv.....
  54.                 Ex_File = Dir                                               '¤U¤@­Ó"A112*ALL_1.csv"
  55.             Loop
  56.         End With
  57.     Next
  58.     Application.ScreenUpdating = True
  59.     MsgBox "OK"
  60. End Sub
½Æ»s¥N½X

TOP

¦^´_ 15# gkld
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook, ar
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  5.     Ex_Path = "C:\Documents and Settings\gkld\®à­±\my kp\¸ê®Æ®w\¤W¥«\"
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "¨S¦³ A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     ar = Array("¥xªd", "¨Èªd", "¹Åªd", "©¯ºÖ", "«H¤j", "ªFªd")
  13.     For i = 1 To 7
  14.         With Sheets(ar(i - 1))                                      '«ü©w©w°}¦C¤¤ªº¤u§@ªí¦WºÙ
  15.             .Range("a1:ag65536").Clear '®ø°£¨C¤@¦æ¸ê®Æ
  16.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  17.             Do While Ex_File <> ""
  18.                 Ex_Date = Replace(Ex_File, "A112", "")                     '®ø°£ÀɦW¤¤"A112"
  19.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '®ø°£ÀɦW¤¤"ALL_1.csv"
  20.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '±a¤J¤é´Á
  21.                 '*****³]¤U¤é´Á±ø¥ó ¤@©P¤ºªº¤é´Á
  22.                 If CDate(Ex_Date) + 6 >= Date Then
  23.                     Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò A11220070102ALL_1.csv.....
  24.                     Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '¨ú±o¸ê®Æ¿é¤Jªº¦C¸¹
  25.                     Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, lookat:=xlWhole)
  26.                     '.Cells(Ex_Row, "A") = Ex_Date  '¤é´Á¿é¤J         '** °O¿ý©Ò¦³¤é´Á***
  27.                     If Not Rng Is Nothing Then
  28.                         .Cells(Ex_Row, "A") = Ex_Date '¤é´Á¿é¤J  ¦p²¾¨ì³o¸Ì '** ¥u°O¿ý¦³¸ê®Æªº¤é´Á
  29.                         .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  30.                         .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  31.                         .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  32.                         .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  33.                         .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  34.                     End If
  35.                     Ex_Wb.Close False                                       'Ãö³¬ A11220070102ALL_1.csv.....
  36.                 End If   '*****  ¤@©P¤ºªº¤é´Á
  37.                 Ex_File = Dir                                               '¤U¤@­Ó"A112*ALL_1.csv"
  38.             Loop
  39.         End With
  40.     Next
  41.     Application.ScreenUpdating = True
  42.     MsgBox "OK"
  43. End Sub
½Æ»s¥N½X

TOP

¦^´_ 17# gkld
§Aªº­×§ï¥i¯àÁÙ¬O¤£¥i¥H ¦]³o¦æ  .Range("a1:ag65536").Clear   '·|®ø°£©Ò¦³ªºÂ¸ê®Æ
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer
  5.     Dim Ar() As String, Wb As Workbook
  6.     'Set Wb = Workbooks.Open("D:\ªÑ²¼¸ê®Æ®w.xls")    '¶}±ÒªÑ²¼¸ê®Æ®wªº¬¡­¶Ã¯
  7.     Ex_Path = "C:\Documents and Settings\gkld\®à­±\my kp\¸ê®Æ®w\¤W¥«\"
  8.    
  9.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  10.     If Ex_File = "" Then
  11.         MsgBox "¨S¦³ A112*ALL_1.csv"
  12.         Exit Sub
  13.     End If
  14.     Application.ScreenUpdating = False
  15.     Ar = Array("¥xªd", "¨Èªd", "¹Åªd", "©¯ºÖ", "«H¤j", "ªFªd")
  16.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  17.     Do While Ex_File <> ""
  18.         Ex_Date = Replace(Ex_File, "A112", "")                     '®ø°£ÀɦW¤¤"A112"
  19.         Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '®ø°£ÀɦW¤¤"ALL_1.csv"
  20.         Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '±a¤J¤é´Á-> Ex_Date
  21.         For i = 1 To 7
  22.             With Sheets(Ar(i - 1))                                      '«ü©w©w°}¦C¤¤ªº¤u§@ªí¦WºÙ
  23.             'With Wb.Sheets(Ar(i - 1))                                 '«ü©w©w°}¦C¤¤ªº¤u§@ªí¤£¦b¦¹µ{§Ç±M®×ªº¬¡­¶Ã¯¤¤
  24.                 If Not .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Exit For
  25.                 '***  ¤£¦A­«½Æ¦³¸ê®Æ  ****'CDate(Ex_Date)¤é´Á -> ¤u§@ªíAÄ椤 §ä¨ì¤é´Á(¦³):Â÷¶}¦^°é
  26.                 'CDate¨ç¼Æ   Date¥ô¦ó¥i¨Ï¥Îªº¤é´Á¹Bºâ¦¡¡C

  27.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò A11220070102ALL_1.csv.....
  28.                 '************************************************
  29.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '¨ú±o¸ê®Æ¿é¤Jªº¦C¸¹
  30.                 Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, LookAt:=xlWhole)
  31.                  '.Cells(Ex_Row, "A") = Ex_Date  '¤é´Á¿é¤J         '** °O¿ý©Ò¦³¤é´Á***
  32.                 If Not Rng Is Nothing Then
  33.                     .Cells(Ex_Row, "A") = Ex_Date '¤é´Á¿é¤J  ¦p²¾¨ì³o¸Ì '** ¥u°O¿ý¦³¸ê®Æªº¤é´Á
  34.                     .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  35.                     .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  36.                     .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  37.                     .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  38.                     .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  39.                 End If
  40.             End With
  41.             Ex_Wb.Close False                                       'Ãö³¬ A11220070102ALL_1.csv.....
  42.             Ex_File = Dir                                               '¤U¤@­Ó"A112*ALL_1.csv"
  43.         Next
  44.     Loop
  45.     Application.ScreenUpdating = True
  46.     MsgBox "OK"
  47. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-3-11 08:25 ½s¿è

¦^´_ 21# gkld
»¡©ú18#µ{¦¡½X½s¼gªºÅÞ¿è
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer
  5.     Dim Ar() As String, Wb As Workbook
  6.     'Set Wb = Workbooks.Open("D:\ªÑ²¼¸ê®Æ®w.xls")    '¶}±ÒªÑ²¼¸ê®Æ®wªº¬¡­¶Ã¯
  7.     Ex_Path = "C:\Documents and Settings\gkld\®à­±\my kp\¸ê®Æ®w\¤W¥«\"   
  8.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  9.     If Ex_File = "" Then
  10.         MsgBox "¨S¦³ A112*ALL_1.csv"
  11.         Exit Sub
  12.     End If
  13.     Application.ScreenUpdating = False
  14.     Ar = Array("¥xªd", "¨Èªd", "¹Åªd", "©¯ºÖ", "«H¤j", "ªFªd")
  15.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  16.     Do While Ex_File <> ""                    ' ´M§ä *.csv  ªº°j°é
  17.          '.............²²¤
  18.         For i = 1 To 7                        '¤u§@ªíªº°j°é
  19.             With Sheets(Ar(i - 1))                                      '«ü©w©w°}¦C¤¤ªº¤u§@ªí¦WºÙ
  20.                 '.............²²¤
  21.                 If Not .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Exit For
  22.                 'If Not .Columns(1).Find °j°é¤ñ¹ï¦b¤u§@ªí¤¤¤ñ¹ï¤é´Áªº If ±ø¥ó¦¡

  23.                  'Exit For:Â÷¶}For i = 1 To 7 ³o¦^°é:¤£¦A­«½Æ¦³ªº¸ê®Æ
  24.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '¶}±Ò ¤£¦s¤é´Á ªº.csv.....
  25.                 '.............²²¤
  26.             End With
  27.             Ex_Wb.Close False                                    'Ãö³¬ A11220070102ALL_1.csv.....
  28.         Next
  29.         '**************************************
  30.         Ex_File = Dir                                            '¤U¤@­Ó"A112*ALL_1.csv"
  31.         'PS 18# ªºµ{¦¡½X¦³¿ù»~:  18# 43¦æµ{¦¡½X  Ex_File = Dir  ¶·²¾¨ì  Loop ªº«e¤@¦æ Ä~Äò§ä¤U¤@­Ó"A112*ALL_1.csv"
  32.     Loop
  33.         '**************************************
  34.     Application.ScreenUpdating = True
  35.     MsgBox "OK"
  36. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¡i°±º¢¤£«e¡A²×µL©Ò±o¡j¤H³£°g©ó´M§ä©_ÂÝ¡A¦]¦Ó°±º¢¤£«e¡FÁa¨Ï®É¶¡¦A¦h¡B¸ô¦Aªø¡A¤]¤FµL¥Î³B¡A²×µL©Ò±o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD