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

[µo°Ý] VBA ¶}±ÒÀÉ®×À³¥Î

¦^´_ 3# Jason80Lo
°Ñ¦Ò¤@¤U
¦P¤@­Ó[¤@¯ë¼Ò²Õ]ªºµ{¦¡½X
  1. Option Explicit
  2. Dim Msg As Boolean, xTime As Variant
  3. '¤@¯ë¼Ò²Õ:Àɮ׶}±Ò®É¦Û°Ê°õ¦æªºµ{§Ç
  4. Sub AUTO_OPEN()  '¨â­Ó«ö¶s¡e¶}©l¡f
  5.     If Msg = True Then Exit Sub
  6.     Msg = True
  7.     Ex
  8. End Sub
  9. '¤@¯ë¼Ò²Õ:ÀÉ®×Ãö³¬®É¦Û°Ê°õ¦æªºµ{§Ç
  10. Sub AUTO_CLOSE() '¨â­Ó«ö¶s¡A[ °±¤î¡f
  11.      Msg = False
  12.      If xTime <> "" Then
  13.         Application.OnTime xTime, "Ex", Schedule:=False  'Ãö³¬¤U¤@­ÓOnTimeªº°õ¦æ
  14.         '³oÀÉ®×Ãö³¬«á,Excel¨SÃö³¬ÁÙ¬O·|°õ¦æOnTimeªºµ{¦¡,·|¦A«×¶}±Ò³oÀÉ®×
  15.         xTime = ""
  16.      End If
  17.      ActiveWorkbook.Save  '¨Ï¥Î¤¤¬¡­¶Ã¯¦sÀÉ
  18. End Sub
  19. Private Sub Ex()
  20.     Dim xPath As String, Rng(1 To 2) As Range, xFile As String, i As Integer
  21.     Dim xString
  22.     xPath = "d:\test\"  'txt Àɮתº¥Ø¿ý
  23.     Set Rng(1) = ActiveWorkbook.Sheets("Sheet1").Rows(1)  ''¨Ï¥Î¤¤¬¡­¶Ã¯,³o¤u§@ªíªº²Ä¤@¦C
  24.     xFile = Dir(xPath & "\*.txt")          '·j´MªþÀɦW
  25.     Do While xFile <> ""                   '§ä¨ì
  26.         Set Rng(2) = Rng(1).Find(xFile, LookAT:=xlWhole) '¤ñ¹ï²Ä¤@¦C¤¤ªº txtÀÉ
  27.         If Rng(2) Is Nothing Then                        '²Ä¤@¦C¤¤¤ñ¹ï¨S¦³³otxtÀÉ
  28.             i = 1
  29.            With Rng(1).Cells(Application.CountA(Rng(1)) + 1) '¨Ì§Ç¦b²Ä¤@¦C¤¤
  30.                 .Cells = xFile                  'ÀɦW¼g¤JÀx¦s®æ¤¤
  31.                 Open xPath & xFile For Input Access Read As #1  '¶}±Ò¤å¦rÀÉ
  32.                 Do Until EOF(1)                 '°õ¦æ°j°éª½¨ìÀɧÀ¬°¤î¡C
  33.                     Line Input #1, xString      '±N¸ê®ÆŪ¤JÅܼƤ¤¡C
  34.                     .Cells(3 + i, 1) = xString  'ÅܼƼg¤JÀx¦s®æ¤¤
  35.                     i = i + 1
  36.                 Loop
  37.                 Close #1    ' Ãö³¬ÀɮסC
  38.             End With
  39.         End If
  40.         xFile = Dir         '¬d¤U¤@­Ó txtÀÉ
  41.     Loop
  42.     xTime = Int(Application.Text(Time, "[m]") / 5) + 1  '²{¦b®É¶¡ªº¤ÀÄÁ¼Æ/5  ªº¾ã¼Æ+ 1
  43.     xTime = DateAdd("N", 5 * xTime, 0)                  '¤U¤@­Ó5¤À¾ã
  44.     Application.OnTime xTime, "Ex"
  45.     Application.StatusBar = "¤U¦¸°õ¦æ®É¶¡ " & xTime
  46. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 8# Jason80Lo
d:\test\

   
  1. xPath = "d:\test\"  'txt Àɮתº¥Ø¿ý
½Æ»s¥N½X
  1. MsgBox xPath & xFile '¬Ý¬Ý
  2. Open xPath & xFile For Input Access Read As #1  
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 10# Jason80Lo
¸Õ¬Ý¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim xTime As Variant
  4.     Application.VBE.Windows("§Y®É¹Bºâ").Visible = True
  5.     '30¬í¡B30¤À¡B3¤p®É
  6.     xTime = Int(Application.Text(Time, "[s]") / 30) + 1
  7.     xTime = DateAdd("s", 30 * xTime, 0)
  8.     Debug.Print "¤U¤@­Ó30¬í¾ã", Time, xTime
  9.     xTime = Int(Application.Text(Time, "[m]") / 30) + 1
  10.     xTime = DateAdd("N", 30 * xTime, 0)
  11.     Debug.Print "¤U¤@­Ó30¤À¾ã", Time, xTime
  12.     xTime = Int(Application.Text(Time, "[h]") / 3) + 1
  13.     xTime = DateAdd("h", 3 * xTime, 0)
  14.     Debug.Print "¤U¤@­Ó3¤p®É¾ã", Time, xTime
  15. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 12# no3-taco

INT ªº¥Î³~¬O§ä¥X,¤ÀÄÁ¼Æ³Q3¾ã°£ªº¾ã¼Æ
  1. Option Explicit
  2. Sub Ex()
  3.     Dim xTime As Variant, nTime As Date
  4.     Application.VBE.Windows("§Y®É¹Bºâ").Visible = True
  5.         nTime = Time
  6.     xTime = Int(Application.Text(nTime, "[m]") / 3) + 1
  7.     xTime = DateAdd("N", 3 * xTime, 0)
  8.     Debug.Print nTime, "²Ä¤@­Ó3¤À¾ã", xTime; "", vbLf
  9.     nTime = xTime
  10.     xTime = Int(Application.Text(xTime, "[m]") / 3) + 1
  11.     xTime = DateAdd("N", 3 * xTime, 0)
  12.     Debug.Print nTime, "¦A¤U­Ó3¤À¾ã", xTime, vbLf
  13.     Debug.Print "§A¬O­n¶¡¹j3¤ÀÄÁ«áªº®É¶¡¦p¤U"
  14.     nTime = Time + #12:03:00 AM#
  15.     Debug.Print Time, "¶¡¹j3¤ÀÄÁ«á", nTime
  16.    
  17. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 14# Jason80Lo
    5¼Óªºµ{¦¡½X¦³¨¾¤î·j´M¨ì«e¦¸·j´M¹LTXTÀɪº§PÂ_¦¡.
  1.   xFile = Dir(xPath & "\*.txt")          '·j´MªþÀɦW
  2. Do While xFile <> ""                   '§ä¨ì
  3.     Set Rng(2) = Rng(1).Find(xFile, LookAT:=xlWhole) '¤ñ¹ï²Ä¤@¦C¤¤ªº txtÀÉ
  4.      '***************************************************
  5.      If Rng(2) Is Nothing Then                        '²Ä¤@¦C¤¤¤ñ¹ï¨S¦³³otxtÀÉ
  6.      '************³o§PÂ_¦¡¤£¬O¶Ü***
  7.           i = 1
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 17# Jason80Lo

¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Private Sub EX()
  3.     Dim xPath As String, Rng(1 To 2) As Range, xFile As String, a As Variant, r As String
  4.     Dim i As Boolean, f As Integer, xString, xMatch As Variant
  5.     Dim S As Worksheet, AR(), x_Row As Integer
  6.    
  7.     If Join(AR, "") = "" Then ReDim AR(0)   '¬°ªÅ°}¦C,°}¦C«Å§i¬°¤@¤¸¯À
  8.     If IsArray([xFile_Add]) Then AR = [xFile_Add]  '·í¬¡­¶Ã¯ªº¦WºÙ¬O°}¦C
  9.     ' [xFile_Add] -> [³o¬¡­¶Ã¯ªº¦WºÙ©Î¨ç¼Æ]
  10.     Set S = ActiveWorkbook.ActiveSheet
  11.     Set Rng(1) = S.Rows(1)                          '¨Ï¥Î¤¤¬¡­¶Ã¯,³o¤u§@ªíªº²Ä¤@¦C
  12.     xPath = "C:\Users\j\Desktop\·s¼W¸ê®Æ§¨ (4)\"    'txt Àɮתº¥Ø¿ý
  13.     xFile = Dir(xPath & "*.txt")                    '·j´MªþÀɦW
  14.     Do While xFile <> ""                            '§ä¨ì
  15.         xMatch = Application.Match(xFile, AR, 0)    '°}¦C¤¤·j´M
  16.         If IsError(xMatch) Then                     '°}¦C¤¤·j´M¨S¦³³otxtÀÉ
  17.             If Join(AR, "") = "" Then
  18.                 AR(0) = xFile                       '°}¦C²Ä¤@¤¸¯À=xFile
  19.             Else
  20.                 ReDim Preserve AR(0 To UBound(AR) + 1) '°}¦C¤W­­¤¸¯À+1
  21.                 AR(UBound(AR)) = xFile
  22.             End If
  23.             Set Rng(2) = Rng(1).Cells(Application.CountA(Rng(1)) + 1) '¨Ì§Ç¦b²Ä¤@¦C¤¤
  24.             i = True
  25.             Rng(2).Cells = xFile                    'ÀɦW¼g¤JÀx¦s®æ¤¤
  26.             f = FreeFile
  27.             Open xPath & xFile For Input Access Read As #1  '¶}±Ò¤å¦rÀÉ
  28.                 Do Until EOF(1)                     '°õ¦æ°j°éª½¨ìÀɧÀ¬°¤î¡C
  29.                     Line Input #1, xString          '±N¸ê®ÆŪ¤JÅܼƤ¤¡C
  30.                     a = Split(xString, Space(1))    '¸ÓÀÉ®×¥H,¬°¤À¹j²Å¸¹
  31.                     'Split ªº«¬ºAVariant
  32.                     If i Then
  33.                         Rng(2).Cells(2, 1).Resize(UBound(a) + 1) = Application.Transpose(a)
  34.                         i = 0
  35.                     Else
  36.                         With Rng(2).End(xlDown).Offset(1)
  37.                             .Resize(UBound(a) + 1) = Application.Transpose(a)
  38.                         End With
  39.                     End If
  40.                 Loop
  41.                 Close #f    ' Ãö³¬ÀɮסC
  42.         End If
  43.         xFile = Dir         '¬d¤U¤@­Ó txtÀÉ
  44.     Loop
  45.     If Join(AR, "") <> "" Then ThisWorkbook.Names.Add "xFile_Add", AR    '³o¬¡­¶Ã¯ªº¦WºÙ ¤º®e¬°³o°}¦C,
  46. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : ¦³Ä@©ñ¦b¤ß¸Ì¡A¨S¦³¨­Åé¤O¦æ¡A¥¿¦p¯Ñ¥Ð¤£¼½ºØ¡A¬Ò¬OªÅ¹L¦]½t¡C
ªð¦^¦Cªí ¤W¤@¥DÃD