返回列表 上一主題 發帖

[發問] 請問有什麼方法可以在excel上自動更新目前所有上市櫃股票收盤價

回復 26# jsleee


再請問 jsleee

1.下載附檔測試後,遇到一個問題,就是『上市』部份無法更新,我將上市的程式合併放進去總表�堙A可是無法執行,請問要如何合併進去。
2.另外,有法子讓檔案開啟時,就自動更新所有的四個工作表,且將四個工作表合併在另一張工作表嗎?

非常謝謝您的指導!
peter460191

TOP

謝謝 jsleee

我還須加一下油!
待我可以下載之後再研究看看 。
peter460191

TOP

回復 21# peter460191


    請將 總表內的程式碼 移到 模組中,即可.....
    請參考附件....

更新收盤價.rar (182.49 KB)

TOP

回復 24# jsleee


    謝謝您!我也快要可以有下載的權限了 !屆時再麻煩您指正了!
peter460191

TOP

回復 23# peter460191

抱歉,我反覆測試,還是遇不到你的問題點.....
再過幾天,也許我的點數夠了,就可以下載你的檔案測試了.....

TOP

回復 22# jsleee


   
麻煩前輩指導。
peter460191

TOP

回復 21# peter460191

很抱歉,我還沒有權限下載檔案....
請將錯誤畫面擷取貼上來.....
這樣才有辦法知道你的問題點

TOP

回復 20# jsleee


   請問  jsleee 及各位達人

我把程式放上去後,會出現錯誤訊息,程式就卡住了, 更新收盤價.rar (179.62 KB)
有附上檔案附件,請幫我看一下,我應該從那部份修正,謝謝您!
peter460191

TOP

回復 25# peter460191

試試看以下的程式碼:但請先在你的 Excel 工作表 建立三個工作表,名稱分別為 "上櫃"、"可轉債"、"興櫃",否則程式會出錯....


Sub 上櫃_可轉債_興櫃()
    '上櫃
    Application.ScreenUpdating = False
    Sheets("上櫃").Select
    DATE_REQ = CDate(Format(Now(), "yyyy/m/d"))
   
PPP1:    yyymmdd = Year(DATE_REQ) - 1911 & Format(Month(DATE_REQ), "00") & Format(Day(DATE_REQ), "00")
    Application.DisplayAlerts = False
    On Error Resume Next
    Cells.Select
    Selection.QueryTable.Delete
    Selection.ClearContents
    Range("A1").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.otc.org.tw/ch/stock/aftertrading/DAILY_CLOSE_quotes/RSTA3104_" & yyymmdd & ".html" _
        , Destination:=Range("$A$1"))
        .Name = "RSTA3104_" & yyymmdd & ""
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    On Error GoTo 0
    Columns("A:A").ColumnWidth = 7
    If Cells(1, "A") = "" Then
        DATE_REQ = DATE_REQ - 1
        GoTo PPP1
    End If

   
    Sheets("可轉債").Select
    yyyymmdd = Year(DATE_REQ) & Format(Month(DATE_REQ), "00") & Format(Day(DATE_REQ), "00")
    On Error Resume Next
    Cells.Select
    Selection.QueryTable.Delete
    Selection.ClearContents
    Range("A1").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.otc.org.tw/ch/inc/js/ReportCSV.php?NAME=/ch/bond_trading_info/bonds_info/daily/data/rsta0113." & yyyymmdd & "-C.csv&SHOW=1&LEVEL=4" _
        , Destination:=Range("$A$1"))
        .Name = "rsta0113." & yyyymmdd & "-C.csv&SHOW=1&LEVEL=4_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    On Error GoTo 0
    Columns("A:A").ColumnWidth = 17.75
   
    '興櫃
    Sheets("興櫃").Select
    Cells.Select
    On Error Resume Next
    Selection.QueryTable.Delete
    Selection.ClearContents
    Range("A1").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://nweb.gretai.org.tw/emgstk/ch/emgstk.htm", Destination:=Range( _
        "$A$1"))
        .Name = "emgstk_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    On Error GoTo 0
    Columns("A:A").ColumnWidth = 15.88
    Columns("B:B").ColumnWidth = 13.13

End Sub

TOP

本帖最後由 peter460191 於 2011-9-16 13:38 編輯

回復 18# peter460191


    再請教  jsleee 前輩

我把全部的程式放在一起,但只會出現一種,想請問要如何讓它同時出現,另外變更日期,除了透過巨集執行外,還有更快或更方便的方法嗎 !請問有方法讓檔案開啟就自動執行最新的日期嗎?
請jsleee 前輩指導一下,再一次感謝您!
peter460191

TOP

        靜思自在 : 忘功不忘過,忘怨不忘恩。
返回列表 上一主題