有在Follow的人是否快吃不消了,有興趣研究畫圖可以參考以下的作法。
Option Explicit Const xlStartYear As Integer = 2014 Const xlStartMonth As Integer = 1 Const xlStartDay As Integer = 1 Sub 大盤與融資() Application.ScreenUpdating = False ClaerChartObjects With Workbooks(1).Worksheets(1) .UsedRange.ClearContents .Cells(1, 1) = "交易日期" .Cells(1, 2) = "大盤指數" .Cells(1, 3) = "上漲家數" .Cells(1, 4) = "下跌家數" .Cells(1, 5) = "持平" .Cells(1, 6) = "未成交" .Cells(1, 7) = "無比價" .Cells(1, 8) = "淨家數" End With 大盤與漲跌家數 Worksheets(1).Cells.EntireColumn.AutoFit Worksheets(1).Cells.HorizontalAlignment = xlCenter 繪圖 Application.ScreenUpdating = True End Sub Sub 大盤與漲跌家數() Dim url As String Dim i, j, k, xlCount As Integer Dim xlTempSheets As Object Set xlTempSheets = Workbooks(1).Worksheets(1) xlCount = 2 For i = xlStartYear To Year(Date) For j = xlStartMonth To Month(Date) For k = xlStartDay To Day(DateSerial(Format(i, "0000"), Format(j, "00") + 1, 1) - 1) url = "http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/MI_INDEX_print.php?genpage=genpage/Report" & Format(i, "0000") & Format(j, "00") & "/A112" & Format(i, "0000") & Format(j, "00") & Format(k, "00") & "MS.php&type=csv" With Workbooks.Open(url) .ActiveSheet.Range("B3:B3").Select If ActiveCell.Value <> Empty Then .ActiveSheet.Range("B3:B3").Copy _ Destination:=xlTempSheets.Range("B" & xlCount & ":B" & xlCount) .ActiveSheet.Range("C106:C108").Copy xlTempSheets.Range("E" & xlCount & ":E" & xlCount).PasteSpecial Transpose:=True xlTempSheets.Cells(xlCount, 1) = Format(i, "0000") & "/" & Format(j, "00") & "/" & Format(k, "00") xlTempSheets.Cells(xlCount, 3) = Split(.ActiveSheet.Range("C104:C104"), "(")(0) xlTempSheets.Cells(xlCount, 4) = Split(.ActiveSheet.Range("C105:C105"), "(")(0) xlTempSheets.Range("H" & xlCount & ":H" & xlCount) = xlTempSheets.Range("C" & xlCount & ":C" & xlCount) - xlTempSheets.Range("D" & xlCount & ":D" & xlCount) xlCount = xlCount + 1 End If .Close 0 End With Next k Next j Next i Set xlTempSheets = Nothing End Sub Sub 繪圖() Dim i, nRow As Integer ClaerChartObjects nRow = Worksheets(1).Range("A65536").End(xlUp).Row With ActiveSheet.ChartObjects.Add(Left:=450, Top:=33, Width:=701, Height:=445).Chart .HasTitle = True .ChartTitle.Text = "大盤與漲跌淨家數" With .SeriesCollection.NewSeries .ChartType = xlLineMarkers '圖表類型 .Values = Range("B2:B" & nRow) 'Y軸數值 .XValues = Range("A2:A" & nRow) 'X軸對應數值 .Name = "大盤" 'Legend圖表名稱 .AxisGroup = xlPrimary '第一條曲線 End With With .SeriesCollection.NewSeries .ChartType = xlLineMarkers '圖表類型 .Values = Range("H2:H" & nRow) 'Y軸數值 .XValues = Range("A2:A" & nRow) 'X軸對應數值 .Name = "漲跌淨家數" 'Legend圖表名稱 .AxisGroup = xlSecondary '第二條曲線 End With With .SeriesCollection.NewSeries .ChartType = xlLineMarkers '圖表類型 .Values = Range("C2:C" & nRow) 'Y軸數值 .XValues = Range("A2:A" & nRow) 'X軸對應數值 .Name = "上漲家數" 'Legend圖表名稱 .AxisGroup = xlSecondary '第三條曲線 End With '.Legend.Delete .Legend.Position = xlBottom 'xlLegendPositionBottom 或 xlBottom都可,若要放上面就用xlTop With .Axes(xlCategory) 'X軸設定 .HasTitle = True '開啟X軸標籤說明 .AxisTitle.Text = Range("A1:A1") '標籤名稱說明 .AxisTitle.Font.Size = 12 '字體大小 End With With .Axes(xlValue, xlPrimary) '左邊 Y軸設定 .HasTitle = True '開啟Y軸標籤說明 .AxisTitle.Text = Range("B1:B1") '標籤名稱說明 .AxisTitle.Font.Size = 12 '字體大小 .AxisTitle.Orientation = xlVertical '字體方向旋轉 .AxisTitle.VerticalAlignment = xlCenter '垂直置中 .AxisTitle.HorizontalAlignment = xlCenter '水平置中 End With With .Axes(xlValue, xlSecondary) '右邊 Y軸設定 .HasTitle = True '開啟Y軸標籤說明 .AxisTitle.Text = "上漲家數、淨家數" '標籤名稱說明 .AxisTitle.Font.Size = 12 '字體大小 .AxisTitle.Orientation = xlVertical '字體方向旋轉 .AxisTitle.VerticalAlignment = xlCenter '垂直置中 .AxisTitle.HorizontalAlignment = xlCenter '水平置中 End With End With 'Color Index : http://msdn.microsoft.com/en-us/library/cc296089(office.12).aspx End Sub Sub ClaerChartObjects() Dim Chtobj As ChartObject For Each Chtobj In ActiveSheet.ChartObjects Chtobj.Delete Next End Sub
執行畫面