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

[µo°Ý] ²{¦b­n¦p¦ó¨ìÃÒ¥æ©Ò¤U¸ü¥~¸ê¦¨¥æ¸ê°T

½Ð°Ý§Ú¬O·Q±NÃÒ¥æ©Òªº¨C¤é¦¬½L¦æ±¡(¤£§tÅvÃÒ¤ûºµÃÒ)¡A¶K¤Wexcel¡A²{¦b¥Îpostªk¸Ó«ç»ò¼gªº
­ì¥»getªk¬O³o¼Ë¼gªº
Sub getSIIPrice()
    urlStr = "URL;http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report" & Format(Sheets("UI").Range("A21").Value, "YYYYMM") & "/A112" & Format(Sheets("UI").Range("A21").Value, "YYYYMMDD") & "ALLBUT0999_1.php?select2=ALLBUT0999&chk_date=" & Year(Sheets("UI").Range("A21").Value) - 1911 & "/" & Format(Sheets("UI").Range("A21").Value, "MM/DD")
    Sheets("SIIPrice").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    With ActiveSheet.QueryTables.Add(Connection:= _
        urlStr _
        , Destination:=Range("A1"))
        .Name = "19"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "10"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
        .Delete
    End With
End Sub

«á¨Ó§Ú±Nºô§}§ï¬°http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/MI_INDEX.php
ActiveSheet.QueryTables.Add¼W¥[¤@­ÓPostText°Ñ¼Æ«o¤£¦æ
½Ð°Ý¸Ó¦p¦ó§ó§ï©O?

TOP

OK ¤F.... ÁÂÁ«ü¾É

TOP

¦^´_ 1# vanguarx
§ï¥ÎPost , ¤j·§¦p¤U¡A¿é¤J¤é´Á©MÀx¦s¸ô®|¦Û¤v§ï¦¨§A­nªº§a~
  1. Sub TestWeb()
  2.     Dim myURL As String
  3.     Dim oStream As Object           'ADODB.Stream
  4.     Dim WinHttpReq As Object            'XMLHTTP
  5.     Dim fileidx As String
  6.     Dim sPost As String
  7.     Dim dteQueryDate As Date
  8.    
  9.     dteQueryDate = #3/11/2015#
  10.    
  11.     myURL = "http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U.php"
  12.     sPost = "download=csv&qdate=" & Format(dteQueryDate, "e/mm/dd") & "&sorting=by_issue"
  13.     sPost = Replace(sPost, "/", "%2F")  'or urlencode
  14.    
  15.     ''¥~¸ê¶R½æ¸ê°T
  16.     Set WinHttpReq = CreateObject("MSXML2.XMLHTTP")
  17.     With WinHttpReq
  18.         .Open "POST", myURL, False
  19.         .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  20.         .setRequestHeader "Content-Length", Len(sPost)
  21.         .Send (sPost)
  22.     End With
  23.    
  24.     Set oStream = CreateObject("ADODB.Stream")
  25.     With oStream
  26.         .Open
  27.         .Type = 1
  28.         .Write WinHttpReq.responseBody
  29.         fileidx = ThisWorkbook.Path & "\" & Format(dteQueryDate, "yyyymmdd") & ".csv"          ''³]©w¤U¸ü¸ô®|¤ÎÀɦW
  30.         On Error Resume Next
  31.         Kill fileidx
  32.         On Error GoTo 0
  33.         .SaveToFile fileidx
  34.         .Close
  35.     End With
  36.    
  37.     Set WinHttpReq = Nothing
  38.     Set oStream = Nothing
  39. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

        ÀR«ä¦Û¦b : °ß¨ä´L­«¦Û¤vªº¤H¡A¤~§ó«i©óÁY¤p¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD