'======程式碼請放在“表單按鈕”裡,,需新增一個名稱為"acc"的工作表================= Private Sub CommandButton1_Click()
Call addlistbox
With Sheets("acc") .Select .Columns.ColumnWidth = 10
stock_id = InputBox("請輸入四碼股票代號" & vbNewLine & "(輸入後,也可以直接修改B2儲存格)") If stock_id = "" Then .Cells.Clear .DrawingObjects.Delete Sheets("sheet1").Select Exit Sub End If .Cells(1, 1) = "股票代號" .Cells(1, 2) = stock_id .Cells(1, 2).Select End With
End Sub
'======程式碼請放在“模組”裡面======
Sub addlistbox()
Dim list_0, list_1, list_2, download
With Sheets("acc") .Cells.Clear .DrawingObjects.Delete Set list_0 = .ListBoxes.Add(.Range("b7").Left + 5, .Range("b7").Top, 100, 100) With list_0 .Name = "list_0" list_0.List = listdata(0) .Selected(1) = True .OnAction = "list_0_change"
End With
Set list_1 = .ListBoxes.Add(.Range("d7").Left + 5, Range("d7").Top, 100, 100) With list_1 .Name = "list_1" list_1.List = listdata(1) .Selected(1) = True .OnAction = "list_1_change" End With
Set list_2 = .ListBoxes.Add(.Range("f7").Left + 5, Range("f7").Top, 100, 100) With list_2 .Name = "list_2" list_2.List = listdata(6) .Selected(1) = True .OnAction = "list_2_change" End With
Set download = .Buttons.Add(.Range("f14").Left + 5, Range("f14").Top, 80, 30) With download .Name = "download" .Caption = "按我下載" .OnAction = "download" End With
Dim HTMLsourcecode, Clipboard As Object Set HTMLsourcecode = CreateObject("htmlfile") Set Clipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
With CreateObject("WinHttp.WinHttpRequest.5.1") .Open "POST", url, False .setRequestHeader "Content-Type", "application/x-www-form-urlencoded" .setRequestHeader "Referer", url_a .setRequestHeader "Cache-Control", "no-cache" .setRequestHeader "Pragma", "no-cache" .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" .setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" .Send
HTMLsourcecode.body.innerhtml = convertraw(.ResponseBody) If InStr(HTMLsourcecode.body.innertext, "查 無 資 料 !!") > 0 Then Sheets("acc").Cells(1, 1) = "查無資料" Exit Sub End If With Clipboard .SetText HTMLsourcecode.body.innerhtml .PutInClipboard End With
With Sheets("acc") .Select .Cells.Clear .Cells(1, 1).Select .PasteSpecial NoHTMLFormatting:=True .Cells(1, 1) = Replace(.Cells(1, 1), "(載入中...)", "") .Cells(2, 1).Select .DrawingObjects.Delete ' .ListBoxes("list_0").Delete ' .ListBoxes("list_1").Delete ' .ListBoxes("list_2").Delete ' .Buttons("download").Delete End With
With Sheets("acc") .ListBoxes("list_1").List = listdata(.ListBoxes("list_0").ListIndex) .ListBoxes("list_1").Selected(1) = True End With
End Sub
Sub list_1_change()
With Sheets("acc") If InStr(.ListBoxes("list_1").List(.ListBoxes("list_1").ListIndex), "季表") = 0 Then .ListBoxes("list_2").List = listdata(5) Else .ListBoxes("list_2").List = listdata(6) End If .ListBoxes("list_2").Selected(1) = True End With
End Sub
Sub list_2_change()
With Sheets("acc") 'debug End With
End Sub
Sub typesetting(accname)
Application.ScreenUpdating = False With Sheets("acc")
If (accname = "CF_M_QUAR_ACC" Or accname = "XX_M_QUAR_ACC") Then shift = 0 Else shift = 1
If .Cells(i, 1) <> "" And (InStr(.Cells(i, 2), "Q") > 0 Or (.Cells(i, 2) <> "-" And .Cells(i, 2) > 1980 And .Cells(i, 3) > 1980) Or .Cells(i + shift, 1) = "") Then With .Range(Cells(i, 1), Cells(i + shift, lastcol)) .Borders(xlEdgeLeft).Weight = xlMedium .Borders(xlEdgeTop).Weight = xlMedium .Borders(xlEdgeBottom).Weight = xlMedium .Borders(xlEdgeRight).Weight = xlMedium .Font.Bold = True .Interior.Color = 16764057 End With .Range(Cells(i, 1), Cells(i, lastcol)).HorizontalAlignment = xlCenter
If shift = 1 Then .Range(Cells(i + 1, 1), Cells(i + 1, lastcol)).HorizontalAlignment = xlRight .Range(Cells(i, 1), Cells(i + 1, 1)).Merge End If
For j = 2 To lastcol Step 2 If shift = 1 Then .Range(Cells(i, j), Cells(i, j + 1)).Merge ' .Columns(j + 1).Font.Bold = True Next j
End If
For k = 2 To lastcol If .Cells(i, k) < 0 Then .Cells(i, k).Font.Color = -16776961 End If Next k If (accname = "XX_M_QUAR_ACC" And .Cells(i, 2) = "") Then .Cells(i, 1) = ""
Next i
If accname = "XX_M_QUAR_ACC" Then Range(Cells(4, 1), Cells(lastrow, lastcol)).SpecialCells(xlCellTypeBlanks, xlErrors).EntireRow.Delete shift:=xlUp End If