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

[µo°Ý] Â^¨ú¨C¤é¦¨¥æ¸ê®Æ

[µo°Ý] Â^¨ú¨C¤é¦¨¥æ¸ê®Æ

test.rar (30.3 KB)

¨Ï¥Î³æ¨B°õ¦æ¨S¤S°ÝÃD ¦ý¬O free run Excel «o¤S ¨S¦³¦^À³ ¥i§_À°¤p§Ì¬Ý¤@¤U ÁÂÁÂ

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-6-2 17:22 ½s¿è

¦^´_ 1# chairmen100
¨Ï¥Î³æ¨B°õ¦æ¨S¤S°ÝÃD ¦ý¬O free run Excel «o¤S ¨S¦³¦^À³

§Aªºµ{¦¡¦³¦b¶],¦ý¤Ó¦hªº°j°é©Ò­P,§A»~¥H¬°¨S¦³¦^À³
­×§ï¤@¤U¸Õ¸Õ¬Ý
  1. Sub ¨C¤é¦¨¥æ¸ê®Æ()
  2. Dim Y As String, m As String, D As String, tse_ymd As String, xlyear As String, tse_web As String
  3. Dim i As Integer, N As Integer, qyt As QueryTable, Dept_Row As Integer, MyStr As String, stkstr As String
  4. Dim Stock_date As Date, objrange As Range
  5. Dim URNG As Range, dic As Object, x As Integer, k As Variant, Msg As Boolean
  6.   '  Application.ScreenUpdating = False  'µù¸Ñ±¼:¬Ýµ{¦¡¦³¦b Run ªº
  7.     Application.DisplayStatusBar = True
  8.     If New½T»{¤u§@ªí("TempG") = False Then Worksheets.Add(after:=Worksheets("¨C¤é¦¨¥æ¸ê®Æ")).Name = "TempG"
  9.     Sheets("¨C¤é¦¨¥æ¸ê®Æ").Select
  10.     'Stock_date = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1")  '¤é´ÁÁÙ­n¥[¤@¤Ñ
  11.     If Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1") = "" Then
  12.         Stock_date = CDate("2014/4/1")
  13.     Else
  14.         Stock_date = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1") + 1 '¤é´ÁÁÙ­n¥[¤@¤Ñ
  15.     End If
  16.     On Error Resume Next
  17.     Do While DateDiff("d", Stock_date, Now()) >= 0
  18.         While Weekday(Stock_date, 2) > 5 'finding work day
  19.             Stock_date = DateAdd("d", 1, Stock_date)
  20.         Wend
  21.         If DateDiff("d", Stock_date, #5/1/2014#) = 0 Then Stock_date = DateAdd("d", 1, Stock_date)
  22.         Y = Format(Year(Stock_date), "0000")
  23.         m = Format(Month(Stock_date), "00")
  24.         D = Format(Day(Stock_date), "00")
  25.         xlyear = CStr(CInt(Y) - 1911)
  26.         tse_ymd = xlyear & "/" & m & "/" & D
  27.         Set objrange = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1").EntireColumn 'shift two col to right
  28.         objrange.Insert (xlShiftToRight)
  29.         
  30.         Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1") = Format(Stock_date, "yyyy/mm/dd")
  31.         For i = 1 To 2
  32.             Sheets("TempG").Cells.Clear
  33.             Sheets("TempG").Cells.ClearContents
  34.             Msg = False
  35.             Select Case i
  36.             Case 1
  37.                 tse_web = "http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report" & Y & m & "/A112" & Y & m & D & "ALLBUT0999_1.php?select2=ALLBUT0999&chk_date=" & tse_ymd
  38.                 stkstr = " ¤W¥«ªÑ»ù........"
  39.                 Application.StatusBar = "Â^¨ú " & tse_ymd & " " & stkstr
  40.                 With Sheets("TempG").QueryTables.Add(Connection:="URL;" & tse_web, Destination:=Sheets("TempG").Range("A1"))
  41.                     'If Err.Number <> 0 Then Err.Clear: MsgBox "¸ê®Æ¬d¸ß¥¢±Ñ"
  42.                     .WebFormatting = xlWebFormattingNone
  43.                     .WebSelectionType = xlSpecifiedTables
  44.                     .WebTables = "10"
  45.                     .Refresh 0
  46.                     If .ResultRange.Count = 2 Or Err <> 0 Then '"¸ê®Æ¬d¸ß¥¢±Ñ"
  47.                         Msg = True
  48.                         GoTo Next_Do
  49.                     End If
  50.                     .Delete
  51.                 End With
  52.             Case 2
  53.                 stkstr = " ¤WÂdªÑ»ù........"
  54.                 Application.StatusBar = "Â^¨ú " & tse_ymd & " " & stkstr
  55.                 tse_web = "http://www.gretai.org.tw/ch/stock/aftertrading/otc_quotes_no1430/stk_wn1430_print.php?d=" & tse_ymd & "&se=EW&s=0,asc,0"
  56.                 With Sheets("TempG").QueryTables.Add(Connection:="URL;" & tse_web, Destination:=Sheets("TempG").Range("A1"))
  57.                     .WebFormatting = xlWebFormattingNone
  58.                     .Refresh 0
  59.                     .Delete
  60.                 End With
  61.         End Select
  62.         Set dic = CreateObject("scripting.dictionary") '¦r¨åª«¥ó
  63.         For Each URNG In Sheets("TempG").UsedRange.Columns(1).Cells
  64.             If VBA.IsNumeric(URNG.Value) = True And Len(URNG.Value) = 4 Then
  65.                 dic(URNG & "," & URNG(1, 2)) = Array(URNG(1, IIf(i = 1, "C", "H")), URNG(1, IIf(i = 1, "I", "C")))
  66.                 ' Call ½Æ»s¨C¤é¦¨¥æ¸ê®Æ(URNG, "¨C¤é¦¨¥æ¸ê®Æ", Dept_Row, i)
  67.                 ' Dept_Row = Dept_Row + 1
  68.              End If
  69.         Next
  70.         'RUN ¤Ó¦h¦¸ Sub ½Æ»s¨C¤é¦¨¥æ¸ê®Æ, ®ö¶O®É¶¡
  71.         With Sheets("¨C¤é¦¨¥æ¸ê®Æ") '¾É¤J¦r¨åª«¥óªºkey , item
  72.             x = 2
  73.             If [count(¨C¤é¦¨¥æ¸ê®Æ!a:a)] = 0 Then  '·í¸ê®Æ¬OªÅ¥Õ®É
  74.                 For Each k In dic.keys
  75.                     .Cells(x, "a") = Split(k, ",")(0)
  76.                     .Cells(x, "b") = Split(k, ",")(1)
  77.                     .Cells(x, "i") = dic(k)(0)
  78.                     .Cells(x, "j") = dic(k)(1)
  79.                     x = x + 1
  80.                 Next
  81.             Else
  82.                 Do While .Cells(x, "a") <> ""
  83.                     k = .Cells(x, "a") & "," & .Cells(x, "b")
  84.                     If dic.exists(k) Then
  85.                         .Cells(x, "i") = dic(k)(0)
  86.                         .Cells(x, "j") = dic(k)(1)
  87.                         dic.Remove k  '²¾°£¦r¨åª«¥óªºkey
  88.                     End If
  89.                     x = x + 1
  90.                 Loop
  91.                 If dic.Count > 0 Then
  92.                     For Each k In dic.keys
  93.                         .Cells(x, "a") = Split(k, ",")(0)
  94.                         .Cells(x, "b") = Split(k, ",")(1)
  95.                         .Cells(x, "i") = dic(k)(0)
  96.                         .Cells(x, "j") = dic(k)(1)
  97.                         x = x + 1
  98.                     Next
  99.                 End If
  100.             End If
  101.         End With
  102.         '*********************
  103.     Next
  104. '============================================================================================================================================================================================
  105. Next_Do:
  106.     If Msg = True Then Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1").EntireColumn.Delete
  107.     Stock_date = DateAdd("d", 1, Stock_date)
  108. Loop
  109.     Application.ScreenUpdating = True
  110.     Application.StatusBar = False
  111.     §R°£¼È¦s¤u§@ªí
  112. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¬Ý¤F¦n¤[!
G¤j! ¯u¬O±j~~~
Happy

TOP

        ÀR«ä¦Û¦b : ­ì½Ì§O¤H´N¬Oµ½«Ý¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD