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

[¤À¨É] ½L¤¤ DDE ¦sÀÉ»P VBA ªº¹ê»ÚÀ³¥Î½d¨Ò

§Ú®tÂI§Ñ¤F»P§Ú¾Ö¦³¤p¾Ç¥Íµ¥¯Åªº¦P¾Ç­Ì¬OµLªk¤U¸üªþ¥óªº¡A
©Ò¥H§Ú¤S±N¥¦ª½±µ¶K¤F¥X¨Ó¡A¤è«K¤j®a¾\Äý¡C
  1. ' ½L¤¤ DDE ¦sÀɪº¹ê»ÚÀ³¥Î½d¨Ò

  2. Option Explicit

  3. Dim actEnabled As Boolean
  4. Dim index As Single

  5. Private Sub Workbook_Open()
  6.     If (Sheets("¤u§@ªí1").Range("AA1").Value = "") Then Sheets("¤u§@ªí1").Range("AA1").Value = "08:45:00"   ' °²³]AA1Äæ¦ì¬°ªÅ¥Õ¡A«h¼g¤J¶}½L°_©l®É¶¡
  7.     If (Sheets("¤u§@ªí1").Range("AA2").Value = "") Then Sheets("¤u§@ªí1").Range("AA2").Value = "13:45:59"   ' AA2Äæ¦ì¥ç¦P¡C(¦¹¨âÄæ¬ö¿ý°_©l²×¤î®É¶¡)
  8.     If (Sheets("¤u§@ªí1").Range("AA3").Value = "") Then Sheets("¤u§@ªí1").Range("AA3").Value = 0            ' ¬ö¿ý³Ì«á¸ê®Æ¶×¤J¤§¦C¸¹ (Rows)¡C
  9.     If (Sheets("¤u§@ªí1").Range("AA4").Value = "") Then Sheets("¤u§@ªí1").Range("AA4").Value = "00:00:10"   ' ¬ö¿ý¸ê®Æ¶×¤J¬Û¹j®É¶¡¡A¦p¨C¹j¤Q¬í¼g¤J¤@¦¸¡C

  10.     If (TimeValue(Now) > Sheets("¤u§@ªí1").Range("AA2").Value) Then       ' ¦pªG¥Ø«e®É¶¡·~¤w¶W¹LAA2ªº®É¬q¡A«h©I¥s.......
  11.         Call stopProcedure
  12.     Else                                                                  ' ¤Ï¤§¡A«h©I¥s.......
  13.         Call startProcedure
  14.     End If
  15. End Sub

  16. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  17.     On Error Resume Next
  18.     Call actStop
  19. End Sub


  20. Private Sub startProcedure()       ' «O¯d§@¬°±±¨î¶µ¤§À³¥Îµ{§Ç¡A¦p«ö¶s¤§¥¨¶°À³¥Îµ¥¡C
  21.     Call actStart
  22. End Sub

  23. Private Sub stopProcedure()        ' «O¯d§@¬°±±¨î¶µ¤§À³¥Îµ{§Ç¡A¦p«ö¶s¤§¥¨¶°À³¥Îµ¥¡C
  24.    Call actStop
  25. End Sub

  26. Sub Starter()
  27.     If (actEnabled = True And TimeValue(Now) >= Sheets("¤u§@ªí1").Range("AA1").Value And TimeValue(Now) <= Sheets("¤u§@ªí1").Range("AA2").Value) Then
  28.         index = Sheets("¤u§@ªí1").Range("AA3").Value

  29.         If (Index = 0) Then Call newTitle  '°²³]newTitleµ{§Ç(¥Ñ¨Ï¥ÎªÌ¦Û¦æ©w¸q)¬O±N²Ä¤@¦Cªº¸ê®Æ©ïÀY¦WºÙ¼g¤J¨ì¤u§@ªí2¡C ¦p¡G¤é´Á¡B®É¶¡¡BR1C5ªº¹ïÀ³Äæ¦ì¸ê®Æµ¥¡C

  30.         Sheets("¤u§@ªí1").Range("AA3").Value = index + 1       ' ¬ö¿ý¦C¸¹¥[¤@¡C
  31.         Sheets("¤u§@ªí2").Cells(index + 2, 1).Value = Date
  32.         Sheets("¤u§@ªí2").Cells(index + 2, 2).Value = TimeValue(Now)
  33.         ' Sheets("¤u§@ªí2").Cells(index + 2, 3).Value = Sheets("¤u§@ªí1").Cells(1, 5).Value
  34.         '
  35.         ' ½Æ»s±q¨é°ÓDDE¶×¤J¤§¬Û¹ïÀ³¦ì¸m¸ê®Æ¡A¦p R1C5 ¹ïÀ³ªº¥i¯à¬O¦¬½L»ùµ¥µ¥¡C
  36.         '
  37.     End If
  38. End Sub


  39. Sub onStarter()
  40.     Call Starter
  41.     If actEnabled Then Call actStart
  42. End Sub

  43. Sub actStart()
  44.     actEnabled = True
  45.     Application.OnTime (Now + Sheets("¤u§@ªí1").Range("AA4").Value), "ThisWorkBook.onStarter"   ' ¼g¤J¸ê®Æªº±Æµ{ (¥Ø«e¬O¨C¹j¤Q¬í¼g¤J¤@¦¸)
  46. End Sub

  47. Sub actStop()
  48.     actEnabled = False

  49.     On Error Resume Next
  50.     Application.OnTime Now, "ThisWorkBook.onStarter", , False
  51. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¯Ê¤fªºªM¤l¡A¦pªG´«¤@­Ó¨¤«×¬Ý¥¦¡A¥¦¤´µM¬O¶êªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD