ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¥Îvba¤U¸üÃÒ¥æ©Òºô­¶(¤é¦¬½L»ù¤Î¤ë¥­§¡¦¬½L»ù)¸ê®Æ

¦^´_ 4# joey0415
ÁÂÁÂjoey0415ªº«ü±Ð
¥i¥H¥¿±`¹B§@¤F

TOP

¦^´_ 3# clianghot546

¤U¸ücsv ¡A¶×¤J¦A§R°£§Y¥i
  1. Sub ­ÓªÑ¤é¦¬½L»ù¤Î¤ë¥­§¡»ùCSV()

  2.     Dim xml As Object
  3.     Dim stream
  4.     Dim URL As String
  5.     ¦~ = 2016
  6.     ¤ë = 2
  7.     ªÑ²¼¥N½X = 2498
  8.     Set xml = CreateObject("Microsoft.XMLHTTP") '¥Î¨Ó¨ú±oºô­¶¸ê®Æ
  9.     Set stream = CreateObject("ADODB.stream")   'ADODB.stream   '¥Î¨ÓÀx¦s¤G¶i¦ìÀÉ®×
  10.     URL = "http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY_AVG/STOCK_DAY_AVGMAIN.php"
  11.     xml.Open "POST", URL, 0
  12.     xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  13.     xml.send "download=csv&query_year=" & ¦~ & "&query_month=" & ¤ë & "&CO_ID=" & ªÑ²¼¥N½X
  14.     With stream
  15.         .Open
  16.         .Type = 1
  17.         .write xml.ResponseBody
  18.         'SaveToFile:ÀɮצWºÙ¤w¦s¦b®É·|¦³¿ù»~,¶·¥ý§R°£¤w¦s¦bªºÀɮצWºÙ
  19.         If Dir(ThisWorkbook.Path & "\" & ªÑ²¼¥N½X & ".CSV") <> "" Then Kill ThisWorkbook.Path & "\" & ªÑ²¼¥N½X & ".CSV"
  20.         .SaveToFile (ThisWorkbook.Path & "\" & ªÑ²¼¥N½X & ".CSV")
  21.         .Close
  22.     End With
  23.    
  24.     Cells.Clear

  25.     With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & ThisWorkbook.Path & "\" & ªÑ²¼¥N½X & ".CSV", Destination:=Range("$A$1"))
  26.         .TextFileCommaDelimiter = True
  27.         .Refresh BackgroundQuery:=False
  28.         .Delete
  29.     End With
  30.    
  31.     Kill ThisWorkbook.Path & "\" & ªÑ²¼¥N½X & ".CSV"
  32.    
  33. End Sub
½Æ»s¥N½X

TOP

¦^´_ 2# joey0415
ÁÂÁÂjoey0415ªº¦^ÂÐ
¤w¸Õ¹L¥i¦æ
¦ý¬O¯à§_¦³ª½±µÃþ¦ü"±qweb"¤U¸ü«áª½±µ¶×¤JexcelÀx¦s®æªº»yªk

TOP

¦^´_ 1# clianghot546
¸Õ¸Õ¬Ý
  1. Sub ­ÓªÑ¤é¦¬½L»ù¤Î¤ë¥­§¡»ùCSV()

  2.     Dim xml As Object
  3.     Dim stream
  4.     Dim URL As String
  5.     ¦~ = 2016
  6.     ¤ë = 2
  7.     ªÑ²¼¥N½X = 1101
  8.     Set xml = CreateObject("Microsoft.XMLHTTP") '¥Î¨Ó¨ú±oºô­¶¸ê®Æ
  9.     Set stream = CreateObject("ADODB.stream")   'ADODB.stream   '¥Î¨ÓÀx¦s¤G¶i¦ìÀÉ®×
  10.     URL = "http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY_AVG/STOCK_DAY_AVGMAIN.php"
  11.     xml.Open "POST", URL, 0
  12.     xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  13.     xml.send "download=csv&query_year=" & ¦~ & "&query_month=" & ¤ë & "&CO_ID=" & ªÑ²¼¥N½X
  14.     With stream
  15.         .Open
  16.         .Type = 1
  17.         .write xml.ResponseBody
  18.         'SaveToFile:ÀɮצWºÙ¤w¦s¦b®É·|¦³¿ù»~,¶·¥ý§R°£¤w¦s¦bªºÀɮצWºÙ
  19.         If Dir("D:\" & ªÑ²¼¥N½X & ".CSV") <> "" Then Kill "D:\" & ªÑ²¼¥N½X & ".CSV"
  20.         .SaveToFile ("D:\" & ªÑ²¼¥N½X & ".CSV")
  21.         .Close
  22.     End With
  23. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¡i°±º¢¤£«e¡A²×µL©Ò±o¡j¤H³£°g©ó´M§ä©_ÂÝ¡A¦]¦Ó°±º¢¤£«e¡FÁa¨Ï®É¶¡¦A¦h¡B¸ô¦Aªø¡A¤]¤FµL¥Î³B¡A²×µL©Ò±o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD