返回列表 上一主題 發帖

有關EXCEL VBA 抓取不到完整網址CSV問題

回復 22# joey0415

想請教大大
下列網址
http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?combination_choice=sub&cno=1&input_date=102/11/06
可不可以也用querytable呢?

TOP

回復 31# jak
  1. Option Explicit
  2. Sub ExA()
  3.     With ActiveSheet
  4.         With .QueryTables.Add("URL;http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?combination_choice=sub&cno=1&input_date=102/11/06", .[A1])
  5.             .WebSelectionType = xlSpecifiedTables
  6.             .WebFormatting = xlWebFormattingNone
  7.             .WebTables = """data_table"""
  8.             .WebPreFormattedTextToColumns = True
  9.             .WebConsecutiveDelimitersAsOne = True
  10.             .WebSingleBlockTextImport = False
  11.             .WebDisableDateRecognition = False
  12.             .WebDisableRedirections = False
  13.             .Refresh BackgroundQuery:=False
  14.         End With
  15.     End With
  16. End Sub
  17. Sub ExB()
  18.     With ActiveSheet
  19.         With .QueryTables(1)
  20.            ' .WebSelectionType = xlSpecifiedTables
  21.            ' .WebFormatting = xlWebFormattingNone
  22.            ' .WebTables = """data_table"""
  23.            ' .WebPreFormattedTextToColumns = True
  24.            ' .WebConsecutiveDelimitersAsOne = True
  25.            ' .WebSingleBlockTextImport = False
  26.            ' .WebDisableDateRecognition = False
  27.            ' .WebDisableRedirections = False
  28.             .Refresh BackgroundQuery:=False
  29.         End With
  30.     End With
  31. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 32# GBKEE

請問超版:


     Sub ExB()
        With ActiveSheet
            With .QueryTables(1)
                .Refresh BackgroundQuery:=False

            End With
        End With
    End Sub

紅字處為什麼還要寫第二個SUB呢?
.QueryTables(1)

這又是什麼呢?是表示有一個QueryTables嗎?
為何又要再一次 .Refresh BackgroundQuery:=False[

謝謝超版

TOP

回復 33# joey0415
Sub ExA() 是新增一個QueryTable
Sub ExB() 是延續這QueryTable中查詢,不必一直用.QueryTables.Add,會佔用資源
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

gbkee,c_c_lai您好:

我也有上述的問題,也是證交所網站問題,但試了很久都沒有結果,可以請教高手是哪裡出錯了嗎? 謝謝您
http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php#
  1. Sub TEST123()
  2.     Dim YMD_day As String, N As Name, webURL As String
  3.     YMD_day = InputBox("輸入 民國年度日期 : 102/10/07", "下載特定日期的資料", Format(Date - 1, "E/MM/DD"))
  4.     With Sheets("下載資料")
  5.        For Each N In .Names
  6.             'N.Delete
  7.        Next
  8.         .Cells.Clear
  9.        GetData_URL = "URL;http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php?edition=ch&filename=genpage/A" & YMD_day & ".dat&type=csv"
  10.         'webURL = "URL; http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?input_date=" & YMD_day & "&login_btn=查詢.dat"
  11.         With .QueryTables.Add(Connection:=GetData_URL, Destination:=.Range("A1"))
  12.             .WebSelectionType = xlSpecifiedTables
  13.             .WebFormatting = xlWebFormattingNone
  14.             .WebTables = "data_table"
  15.             .WebPreFormattedTextToColumns = True
  16.             .WebConsecutiveDelimitersAsOne = False
  17.             .WebSingleBlockTextImport = False
  18.             .WebDisableDateRecognition = False
  19.             .WebDisableRedirections = True
  20.             .Refresh BackgroundQuery:=False
  21.         End With
  22.     End With
  23. End Sub
複製代碼

TOP

有關EXCEL VBA 抓取不到完整網址CSV問題

各位高手您好,

因要抓先前已爬文,http://forum.twbts.com/viewthread.php?tid=10770,修改過後,資仍帶不出來,請想問各位高手是否php後面的語法使用有誤,謝謝大家^^

http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php
  1. Option Explicit
  2. Sub ExA()
  3.     With ActiveSheet
  4.         With .QueryTables.Add("URL;http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php#?combination_choice=sub&cno=1&input_date=103/02/25", .[A1])
  5.             .WebSelectionType = xlSpecifiedTables
  6.             .WebFormatting = xlWebFormattingNone
  7.             .WebTables = """data_table"""
  8.             .WebPreFormattedTextToColumns = True
  9.             .WebConsecutiveDelimitersAsOne = True
  10.             .WebSingleBlockTextImport = False
  11.             .WebDisableDateRecognition = False
  12.             .WebDisableRedirections = False
  13.             .Refresh BackgroundQuery:=False
  14.         End With
  15.     End With
  16. End Sub
複製代碼
  1. Sub TEST123()
  2.     Dim YMD_day As String, N As Name, webURL As String
  3.     YMD_day = InputBox("輸入 民國年度日期 : 102/10/07", "下載特定日期的資料", Format(Date - 1, "E/MM/DD"))
  4.     With Sheets("下載資料")
  5.        For Each N In .Names
  6.             'N.Delete
  7.        Next
  8.         .Cells.Clear
  9.        GetData_URL = "URL;http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php?edition=ch&filename=genpage/A" & YMD_day & ".dat&type=csv"
  10.         'webURL = "URL; http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?input_date=" & YMD_day & "&login_btn=查詢.dat"
  11.         With .QueryTables.Add(Connection:=GetData_URL, Destination:=.Range("A1"))
  12.             .WebSelectionType = xlSpecifiedTables
  13.             .WebFormatting = xlWebFormattingNone
  14.             .WebTables = "data_table"
  15.             .WebPreFormattedTextToColumns = True
  16.             .WebConsecutiveDelimitersAsOne = False
  17.             .WebSingleBlockTextImport = False
  18.             .WebDisableDateRecognition = False
  19.             .WebDisableRedirections = True
  20.             .Refresh BackgroundQuery:=False
  21.         End With
  22.     End With
  23. End Sub
複製代碼

請試用一下吧

Sub TWT93U()
'
'
' 信用額度總量管制餘額表  @ TWSE 臺灣證券交易所 ﹥交易資訊 ﹥融資融券與可借券賣出額度 ﹥融券借券賣出餘額
' http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php
Dim YMD_day As String, N As Name, webURL As String
    YMD_day = Format(Date, "E/MM/DD")
    With Sheets("Sheet1")
        For Each N In .Names
            N.Delete
        Next
        .Cells.Clear
        webURL = "URL;http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php?input_date=" & YMD_day & "&login_btn=查詢.dat"
        With .QueryTables.Add(Connection:=webURL, Destination:=.Range("A1"))
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "7,9"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = False
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = True
            .Refresh BackgroundQuery:=False
        End With
    End With
End Sub
很抱歉,我是小學生,不能下載檔案,是個小屁孩!

TOP

回復 35# gto1208
改好了,請試用吧!

    Sub TEST123()
        Dim YMD_day As String, N As Name, webURL As String
        YMD_day = InputBox("輸入 民國年度日期 : 102/10/07", "下載特定日期的資料", Format(Date - 1, "E/MM/DD"))
        With Sheets("下載資料")
           For Each N In .Names
                'N.Delete
           Next
            .Cells.Clear
            GetData_URL = "URL;http://www.twse.com.tw/ch/trading/exchange/TWT93U/TWT93U.php?edition=ch&filename=genpage/A" & YMD_day & ".dat&type=csv"
            'webURL = "URL; http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?input_date=" & YMD_day & "&login_btn=查詢.dat"
            With .QueryTables.Add(Connection:=GetData_URL, Destination:=.Range("A1"))
                 .WebSelectionType = xlSpecifiedTables
                 .WebFormatting = xlWebFormattingNone
                 .WebTables = "9"
                 .WebPreFormattedTextToColumns = True
                 .WebConsecutiveDelimitersAsOne = False
                 .WebSingleBlockTextImport = False
                 .WebDisableDateRecognition = False
                 .WebDisableRedirections = True
                 .Refresh BackgroundQuery:=False
             End With
            End With
        End With
    End Sub
很抱歉,我是小學生,不能下載檔案,是個小屁孩!

TOP

謝謝高手  太感謝了

TOP

heavenweaver 您好

我目前有二個網址
http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php
http://www.gretai.org.tw/ch/stock/statistics/monthly/st44.php

都是屬於上述的狀況,我想請教一下,是否有工具可以查詢?edition=ch&filename=genpage/A" & YMD_day & ".dat&type=csv" --的參數資料出來呢,謝謝

TOP

        靜思自在 : 小事不做、大事難成。
返回列表 上一主題