看板 Office 關於我們 聯絡資訊
※ 引述《hitoo (◎☑)》之銘言: : ※ [本文轉錄自 Stock 看板] : 作者: hitoo (◎☑) 看板: Stock : 標題: [請益] 不知道大家都怎麼抓觀測站的數據? : 時間: Sat Sep 27 01:12:43 2008 : 例如: : http://0rz.tw/8b4Px : 右鍵傳送至Excel 2003(有點想換2007,如果可以更方便的話!) : 然後一個儲存格(現金流量表) : 本期淨利 $ 26,900,099 $ 26,206,151 : 1.我要怎麼把他切成三個儲存格? : 2.要怎麼只取前幾個位數呢? 我想要269億! : 3.例如我只要2002的最近五年的損益表,只能一個一個開嗎? : 應該有更快地方法讓他自己跑吧! : 請教一下大家,謝謝! A欄放你要的股票代號, 2002, 1301... 最好抓到前一年就好,這一年的在另外抓~~ Sub Ptt() Dim Fn As Object Set Fn = Application.WorksheetFunction yearstart = 2000 yearend = 2007 tempvalue = 0 For i = 1 To 2 co_id = Cells(i, 1) For j = yearstart To yearend For k = 1 To 4 yearseason = j & "0" & k With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://mops.twse.com.tw/nas/t06sa18/" & yearseason & "/A02_" & co_id & "_" & yearseason & ".htm", _ Destination:=Range("B1")) .Name = "PTT" .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 = "4" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With For l = 1 To 16 teststring = Fn.Trim(Cells(30 + l, 2)) test = Mid(teststring, 1, 4) If test = "本期淨利" Then temp = Cells(30 + l, 3) tempvalue = tempvalue + 1 Sheets("sheet2").Cells(tempvalue, 1) = co_id Sheets("sheet2").Cells(tempvalue, 2) = yearseason Sheets("sheet2").Cells(tempvalue, 3) = temp Exit For Else temp = "" End If Next ActiveSheet.Range("B:H").Delete Next Next Next End Sub -- 我打研究室走過 那獨坐電腦前的容顏如苦瓜的糾結 靈感不來 長壽的煙霧不散 研究室如小小的寂寞的城 恰如商管的電梯向晚 http://chungyuandye.blogspot.com -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.173.139.172
hitoo:謝謝 09/28 11:54
JieJuen:推 09/28 19:01
JieJuen:嗯 不過與原po需求不太相同 09/29 01:19