·sª©ªÑ¥«¤½¶}¸ê°TÆ[´ú¯¸ªº¸ê®Æ§ì¨ìEXECL?
- ©«¤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
        
|
¦^´_ 38# chang0833
¸Õ¸Õ¬Ý- Option Explicit
- Sub Ex()
- Dim URL As String, xCo_Id As String, X As Integer
- Dim xSyear As Integer, xSseason As Integer, Ar(1 To 4)
- Dim Sh(1 To 2) As Worksheet, AY, Rng As Range, E As Variant
- Dim Wb As Workbook
- For X = 0 To 3
- Ar(X + 1) = 1 + (6 * X) '²Ä¤@©u¨ì²Ä¥|©uªºÄæ¦ì
- Next
- xCo_Id = Application.InputBox("½Ð¿é¤JªÑ²¼¥N¸¹", , 2303) '¹w³]¬° 2303
- X = Year(Date) - 1910 '¤¤µØ¥Á°êªº¦~«×
- Application.ScreenUpdating = False
- Set Wb = Workbooks("book1.xls") '«ü©w¬¡¶Ã¯
- With Wb
- Set Sh(1) = .Sheets.Add '·s¼W¤u§@ªí: ½Æ»s©u°]³ø¨ì«ü©w¤u§@¶
- Set Sh(2) = .Sheets.Add '·s¼W¤u§@ªí: WEB¬d¸ß¥Î
- End With
- On Error GoTo Er '³B²zµ{¦¡¤Wªº¿ù»~
- Sh(1).Name = xCo_Id & "©u³øªí" '³o¦WºÙ¤u§@ªí¦p¤w¦s¦bµ{¦¡·|¦³¿ù»~
- On Error GoTo 0 '¤£¦b³B²zµ{¦¡¤Wªº¿ù»~
-
- For xSyear = X To X - 3 Step -1 '°j°é:¦~«× '105->102
- 'For xSyear = X - 3 To X '°j°é:¦~«× '102->105
- For xSseason = 1 To 4 ' '°j°é:©u§O '1,2,3,4
- URL = "URL;http://mops.twse.com.tw/server-java/t164sb01?step=1&CO_ID=" & xCo_Id & "&SYEAR=" & xSyear & "&SSEASON=" & xSseason & "&REPORT_ID=C"
- With Sh(2).QueryTables.Add(Connection:=URL, Destination:=Sh(2).[A1])
- .Name = xCo_Id & "_" & xSyear & "_²Ä" & xSseason & "©u" 'WEB¬d¸ßªº¦WºÙ
- .AdjustColumnWidth = True '¦Û°Ê½Õ¾ãÄæ¼e
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "2,3,4" '¸ê²£t¶Åªí,ºî¦X·l¯qªí,²{ª÷¬y¶qªí
- .WebPreFormattedTextToColumns = True
- .WebConsecutiveDelimitersAsOne = True
- .WebSingleBlockTextImport = False
- .WebDisableDateRecognition = False
- .WebDisableRedirections = False
- .Refresh BackgroundQuery:=False
- If .ResultRange.Rows.Count > 2 Then '¦³¸ê®Æ
- Set Rng = Sh(1).Cells(1, Ar(xSseason)).Cells(Rows.Count).End(xlUp)
- If Rng.Row > 1 Then Set Rng = Rng.Offset(2)
- .ResultRange.Copy Rng
- Else
- .Delete
- End If
-
- End With
- Next
- Next
- Application.DisplayAlerts = False
- Sh(2).Delete
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- Sh(1).Parent.Save
- MsgBox "Ok"
- Exit Sub
- Er: '³B²z xCo_Id &©u³øªí ¤u§@ªí¤w¦s¦b
- Application.DisplayAlerts = False
- Sheets(xCo_Id & "©u³øªí").Delete
- Application.DisplayAlerts = True
- Resume Next '¦^¨ì¿ù»~ªºµ{¦¡½X
- End Sub
½Æ»s¥N½X |
|
|
|
|
|
|
- ©«¤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
        
|
¦^´_ 42# chang0833
¬O³o¼Ë¶Ü?- Option Explicit
- Sub Ex()
- Dim URL As String, xCo_Id As String
- Dim xSyear As Integer, xSseason As Integer
- Dim Sh(1 To 2) As Worksheet, Rng As Range
-
- xCo_Id = Application.InputBox("½Ð¿é¤JªÑ²¼¥N¸¹", , 2303) '¹w³]¬° 2303
- xSyear = Format(Date, "E") '¤¤µØ¥Á°êªº¦~«×
- xSseason = DatePart("q", Date) '·í©u
- Application.ScreenUpdating = False
- 'Set Wb = ThisWorkbook '«ü©w¬¡¶Ã¯
- With ThisWorkbook '«ü©w¬¡¶Ã¯
- Set Sh(1) = .Sheets.Add '·s¼W¤u§@ªí: ½Æ»s©u°]³ø¨ì«ü©w¤u§@¶
- Set Sh(2) = .Sheets.Add '·s¼W¤u§@ªí: WEB¬d¸ß¥Î
- End With
- On Error GoTo Er '³B²zµ{¦¡¤Wªº¿ù»~
- Application.DisplayAlerts = False
- Sh(1).Name = xCo_Id & "©u³øªí" '³o¦WºÙ¤u§@ªí¦p¤w¦s¦bµ{¦¡·|¦³¿ù»~
- Set Rng = Sh(1).[A1]
- On Error GoTo 0 '¤£¦A³B²zµ{¦¡¤Wªº¿ù»~
-
- Do
- URL = "URL;http://mops.twse.com.tw/server-java/t164sb01?step=1&CO_ID=" & xCo_Id & "&SYEAR=" & xSyear & "&SSEASON=" & xSseason & "&REPORT_ID=C"
- With Sh(2).QueryTables.Add(Connection:=URL, Destination:=Sh(2).[A1])
- .Name = xCo_Id & "_" & xSyear & "_²Ä" & xSseason & "©u" 'WEB¬d¸ßªº¦WºÙ
- .AdjustColumnWidth = True '¦Û°Ê½Õ¾ãÄæ¼e
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "2,3,4" '¸ê²£t¶Åªí,ºî¦X·l¯qªí,²{ª÷¬y¶qªí
- .WebPreFormattedTextToColumns = True
- .WebConsecutiveDelimitersAsOne = True
- .WebSingleBlockTextImport = False
- .WebDisableDateRecognition = False
- .WebDisableRedirections = False
- .Refresh BackgroundQuery:=False
- If .ResultRange.Rows.Count > 2 Then '¦³¸ê®Æ
- Debug.Print xSyear, xSseason, Rng.Address
- .ResultRange.Copy Rng
- Set Rng = Rng.Offset(, .ResultRange.Columns.Count + 1)
- Else
- .Delete
- End If
- End With
- xSseason = xSseason - 1
- If xSseason = 0 Then
- xSseason = 4
- xSyear = xSyear - 1
- End If
- Loop Until xSyear = Format(Date, "E") - 3
-
- Sh(2).Delete
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- ' Sh(1).Parent.Save
- MsgBox "Ok"
- Exit Sub
- Er: '³B²z xCo_Id &©u³øªí ¤u§@ªí¤w¦s¦b
- Sheets(xCo_Id & "©u³øªí").Delete 'Âл\ì¤u§@¶¶Ü¡H(¥u¯d¤U³Ì«á§ó·sªº¸ê®Æ)
-
- Resume '¦^¨ì¿ù»~ªºµ{¦¡½X
- End Sub
½Æ»s¥N½X |
|
|
|
|
|
|
- ©«¤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 ©ó 2016-12-24 09:07 ½s¿è
¦^´_ 47# jasonwu0114
¸Õ¸Õ¬Ý- Option Explicit
- Sub Ex()
- Dim URL As String, xCo_Id As Range, xSyear As String, xSseason As String, i As Integer, M As Variant
- xSyear = 105
- xSseason = 3
- For i = 1 To 20 '¶]20-30ӪѲ¼¥N¸¹
- Set xCo_Id = Sheets(1).Cells(i, "A") 'ªÑ²¼¥N¸¹
- URL = "URL;http://mops.twse.com.tw/server-java/t164sb01?step=1&CO_ID=" & xCo_Id & "&SYEAR=" & xSyear & "&SSEASON=" & xSseason & "&REPORT_ID=C"
- With SheetS(2).QueryTables.Add(Connection:=URL, Destination:=Sheets(2).Range("A1"))
- .AdjustColumnWidth = False '¦Û°Ê½Õ¾ãÄæ¼e
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "2" ',3,4" '¸ê²£t¶Åªí,ºî¦X·l¯qªí,²{ª÷¬y¶qªí
- .WebPreFormattedTextToColumns = True
- .WebConsecutiveDelimitersAsOne = True
- .WebSingleBlockTextImport = False
- .WebDisableDateRecognition = False
- .WebDisableRedirections = False
- .Refresh BackgroundQuery:=False
- With .ResultRange '©Ò¶×¤J¸ê®Æªº½d³ò
- M = Application.Match("*À³¥Iµu´Á²¼¨é¦Xp", .Columns(1), 0) '¤u§@ªí¨ç¼Æ¦b²Ä¤@Ä椤¶Ç¦^¤ñ¹ï¨ìªºÄæ¦ì
- If IsNumeric(M) Then xCo_Id.Offset(, 1) = .Cells(M, "b") '¦³¤ñ¹ï¨ì¶Ç¦^ªºÄæ¦ìªº¼Æ¦r
- .Clear
- End With
- .Parent.Names(.Name).Delete '§R°£¤u§@ªíªº¦WºÙ
- .Delete ''³oQueryTable§R°£±¼
- End With
- Next
- End Sub
½Æ»s¥N½X |
|
|
|
|
|
|