
最好抓到前一年就好,這一年的在另外抓~~
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
讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~