- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¥»©«³Ì«á¥Ñ 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¸Õ¸Õ¬Ý- Sub ¨C¤é¦¨¥æ¸ê®Æ()
- Dim Y As String, m As String, D As String, tse_ymd As String, xlyear As String, tse_web As String
- Dim i As Integer, N As Integer, qyt As QueryTable, Dept_Row As Integer, MyStr As String, stkstr As String
- Dim Stock_date As Date, objrange As Range
- Dim URNG As Range, dic As Object, x As Integer, k As Variant, Msg As Boolean
- ' Application.ScreenUpdating = False 'µù¸Ñ±¼:¬Ýµ{¦¡¦³¦b Run ªº
- Application.DisplayStatusBar = True
- If New½T»{¤u§@ªí("TempG") = False Then Worksheets.Add(after:=Worksheets("¨C¤é¦¨¥æ¸ê®Æ")).Name = "TempG"
- Sheets("¨C¤é¦¨¥æ¸ê®Æ").Select
- 'Stock_date = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1") '¤é´ÁÁÙn¥[¤@¤Ñ
- If Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1") = "" Then
- Stock_date = CDate("2014/4/1")
- Else
- Stock_date = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1") + 1 '¤é´ÁÁÙn¥[¤@¤Ñ
- End If
- On Error Resume Next
- Do While DateDiff("d", Stock_date, Now()) >= 0
- While Weekday(Stock_date, 2) > 5 'finding work day
- Stock_date = DateAdd("d", 1, Stock_date)
- Wend
- If DateDiff("d", Stock_date, #5/1/2014#) = 0 Then Stock_date = DateAdd("d", 1, Stock_date)
- Y = Format(Year(Stock_date), "0000")
- m = Format(Month(Stock_date), "00")
- D = Format(Day(Stock_date), "00")
- xlyear = CStr(CInt(Y) - 1911)
- tse_ymd = xlyear & "/" & m & "/" & D
- Set objrange = Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1").EntireColumn 'shift two col to right
- objrange.Insert (xlShiftToRight)
-
- Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1") = Format(Stock_date, "yyyy/mm/dd")
- For i = 1 To 2
- Sheets("TempG").Cells.Clear
- Sheets("TempG").Cells.ClearContents
- Msg = False
- Select Case i
- Case 1
- 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
- stkstr = " ¤W¥«ªÑ»ù........"
- Application.StatusBar = "Â^¨ú " & tse_ymd & " " & stkstr
- With Sheets("TempG").QueryTables.Add(Connection:="URL;" & tse_web, Destination:=Sheets("TempG").Range("A1"))
- 'If Err.Number <> 0 Then Err.Clear: MsgBox "¸ê®Æ¬d¸ß¥¢±Ñ"
- .WebFormatting = xlWebFormattingNone
- .WebSelectionType = xlSpecifiedTables
- .WebTables = "10"
- .Refresh 0
- If .ResultRange.Count = 2 Or Err <> 0 Then '"¸ê®Æ¬d¸ß¥¢±Ñ"
- Msg = True
- GoTo Next_Do
- End If
- .Delete
- End With
- Case 2
- stkstr = " ¤WÂdªÑ»ù........"
- Application.StatusBar = "Â^¨ú " & tse_ymd & " " & stkstr
- 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"
- With Sheets("TempG").QueryTables.Add(Connection:="URL;" & tse_web, Destination:=Sheets("TempG").Range("A1"))
- .WebFormatting = xlWebFormattingNone
- .Refresh 0
- .Delete
- End With
- End Select
- Set dic = CreateObject("scripting.dictionary") '¦r¨åª«¥ó
- For Each URNG In Sheets("TempG").UsedRange.Columns(1).Cells
- If VBA.IsNumeric(URNG.Value) = True And Len(URNG.Value) = 4 Then
- dic(URNG & "," & URNG(1, 2)) = Array(URNG(1, IIf(i = 1, "C", "H")), URNG(1, IIf(i = 1, "I", "C")))
- ' Call ½Æ»s¨C¤é¦¨¥æ¸ê®Æ(URNG, "¨C¤é¦¨¥æ¸ê®Æ", Dept_Row, i)
- ' Dept_Row = Dept_Row + 1
- End If
- Next
- 'RUN ¤Ó¦h¦¸ Sub ½Æ»s¨C¤é¦¨¥æ¸ê®Æ, ®ö¶O®É¶¡
- With Sheets("¨C¤é¦¨¥æ¸ê®Æ") '¾É¤J¦r¨åª«¥óªºkey , item
- x = 2
- If [count(¨C¤é¦¨¥æ¸ê®Æ!a:a)] = 0 Then '·í¸ê®Æ¬OªÅ¥Õ®É
- For Each k In dic.keys
- .Cells(x, "a") = Split(k, ",")(0)
- .Cells(x, "b") = Split(k, ",")(1)
- .Cells(x, "i") = dic(k)(0)
- .Cells(x, "j") = dic(k)(1)
- x = x + 1
- Next
- Else
- Do While .Cells(x, "a") <> ""
- k = .Cells(x, "a") & "," & .Cells(x, "b")
- If dic.exists(k) Then
- .Cells(x, "i") = dic(k)(0)
- .Cells(x, "j") = dic(k)(1)
- dic.Remove k '²¾°£¦r¨åª«¥óªºkey
- End If
- x = x + 1
- Loop
- If dic.Count > 0 Then
- For Each k In dic.keys
- .Cells(x, "a") = Split(k, ",")(0)
- .Cells(x, "b") = Split(k, ",")(1)
- .Cells(x, "i") = dic(k)(0)
- .Cells(x, "j") = dic(k)(1)
- x = x + 1
- Next
- End If
- End If
- End With
- '*********************
- Next
- '============================================================================================================================================================================================
- Next_Do:
- If Msg = True Then Sheets("¨C¤é¦¨¥æ¸ê®Æ").Range("I1:J1").EntireColumn.Delete
- Stock_date = DateAdd("d", 1, Stock_date)
- Loop
- Application.ScreenUpdating = True
- Application.StatusBar = False
- §R°£¼È¦s¤u§@ªí
- End Sub
½Æ»s¥N½X |
|