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

[µo°Ý] ¨Ï¥Î¤¸¤jÃÒYeswinªºRTD¤¸¥ó§Y®É§ó·sªÑ»ù°ÝÃD??

¦^´_ 1# jasonwu0114
¦Û»s¬Ý½L



ThisWorkbook µ{¦¡½X
  1. Option Explicit
  2. Dim ie()  As Object
  3. Const Sh = "¬Ý½L"  '«ü©w¤u§@ªí¦WºÙ
  4. Private Sub Workbook_Open()
  5.     Dim i As Integer, T As Date
  6.     Workbook_BeforeClose False
  7.     With Sheets(Sh)
  8.         Application.StatusBar = "ºô­¶¤U¸ü¤¤..."
  9.         For i = 2 To .UsedRange.Columns(1).Rows.Count  'ªÑ²¼¥N¸¹
  10.             ReDim Preserve ie(2 To i)
  11.             If .Cells(i, "A") <> "" And IsNumeric(.Cells(i, "A")) And Len(.Cells(i, "A")) >= 4 Then
  12.                 Set ie(i) = CreateObject("InternetExplorer.Application")
  13.                 ie(i).Navigate "http://newmis.twse.com.tw/stock/fibest.jsp?stock=" & .Cells(i, "A")
  14.                 DoEvents
  15.                 Application.StatusBar = "¤U¸ü... " & .Cells(i, "A")
  16.                 ie(i).Visible = False
  17.             Else
  18.                 Set ie(i) = Nothing
  19.                 .UsedRange.Rows(i).Offset(, 1) = ""
  20.             End If
  21.         Next
  22.     End With
  23.     T = Time + #12:00:05 AM#
  24.     If Time < #9:00:00 AM# Then T = #9:00:00 AM#
  25.     Application.OnTime T, "ThisWorkbook.©Ò¦³ªÑ»ù"
  26. End Sub
  27. Private Sub §Y®ÉªÑ»ù(R As Integer)
  28.     Dim Element As Object, C As Integer
  29.     Application.EnableEvents = False
  30.     With Sheets(Sh)
  31.         If Not ie(R) Is Nothing Then
  32.             With ie(R)
  33.                 Do While .Busy Or .ReadyState <> 4: Loop
  34.                 Set Element = .document.getElementsByTagName("TABLE")(1) '
  35.             End With
  36.             For C = 0 To Element.Rows(1).Cells.Length - 1
  37.                 .Cells(R, C + 2) = Element.Rows(1).Cells(C).innertext
  38.             Next
  39.         Else
  40.             .UsedRange.Rows(R).Offset(, 1) = ""
  41.         End If
  42.     End With
  43.     Application.EnableEvents = True
  44. End Sub

  45. Private Sub ©Ò¦³ªÑ»ù()
  46.     Dim R As Integer
  47.     If Time >= #1:30:00 PM# Then
  48.         Workbook_BeforeClose False
  49.         Application.StatusBar = "  ¤w¦¬½L!!!"
  50.         Exit Sub
  51.     End If
  52.     For R = 2 To UBound(ie)
  53.         §Y®ÉªÑ»ù R
  54.     Next
  55.     Application.OnTime Time + #12:00:02 AM#, "ThisWorkbook.©Ò¦³ªÑ»ù"
  56.     Application.StatusBar = Time & vbTab & "§ó·s§¹¦¨"
  57. End Sub
  58. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  59.     Dim e As Variant
  60.     On Error Resume Next
  61.     For Each e In ie
  62.        e.Quit
  63.        Set e = Nothing
  64.     Next
  65. End Sub
  66. Private Sub Workbook_SheetChange(ByVal Wsh As Object, ByVal Target As Range)
  67.     If Wsh.Name = Sh Then
  68.         If Target.Column = 1 And Target.Row > 1 Then Workbook_Open
  69.     End If
  70. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡¦¨´N¤@¤Á¡j®É¶¡¥i¥H³y´N¤H®æ¡A¥i¥H¦¨´N¨Æ·~¡A¤]¥i¥HÀx¿n¥\¼w¡C
ªð¦^¦Cªí ¤W¤@¥DÃD