返回列表 上一主題 發帖

[發問] [請教]個股成交資訊以VBA擷取之問題...

回復 2# chen_cook


謝謝大大, 我有試過可行了!!

另外請問...
以下這二種寫法的意義有不同嗎?
為啥第一種就得不出data呢?是不是少寫什麼??
(第二種比較看得懂,因為寫IQY時也是以連到相同的URL去抓data)
  1.     With ActiveSheet.QueryTables.Add(Connection:= _
  2.         "URL;http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php" _
  3.         , Destination:=Range("A1"))
  4.         .PostText = "ajax=true&myear=" & myear & "&mmon=" & mmon & "&STK_NO=" & STK_NO
複製代碼
  1.      With ActiveSheet.QueryTables.Add(Connection:= _
  2.          "URL;http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/genpage/Report" & mym & "/" & mym & "_F3_1_8_" & STK_NO & ".php?STK_NO=" & STK_NO & "&myear=" & myear & "&mmon=" & mmon _
  3.         , Destination:=Range("A1"))
  4. '
複製代碼
新手上路

TOP

回復 1# cudui


    Sub 個股日成交資訊()
'
'
    Dim ptxt As String
    'Dim STK_NO, mmon As String
    myear = InputBox("輸入查詢民國年", "個股日成交資訊")
   
    If myear = "" Then
       Exit Sub
    Else
       myear = myear + 1911
    End If
    mmon = InputBox("輸入查詢月,1-9月需補0如02月", "個股日成交資訊")
    If mmon = "" Then Exit Sub
   
    STK_NO = InputBox("輸入個股代碼", "個股日成交資訊")
    If STK_NO = "" Then Exit Sub
           
    mym = myear & mmon
     With ActiveSheet.QueryTables.Add(Connection:= _
         "URL;http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/genpage/Report" & mym & "/" & mym & "_F3_1_8_" & STK_NO & ".php?STK_NO=" & STK_NO & "&myear=" & myear & "&mmon=" & mmon _
        , Destination:=Range("A1"))
'
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = False
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingAll
        .WebTables = "8"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
           
   
End Sub

     試試看吧!!

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題