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

[µo°Ý] ³ÌªñµLªk¤U¸üµý¥æ©Ò¥æ©ö¸ê®Æ

[µo°Ý] ³ÌªñµLªk¤U¸üµý¥æ©Ò¥æ©ö¸ê®Æ

¹L¥h¥Î¤U¦Cµ{¦¡¥i¥H¤U¸üµý¥æ©Ò¨C¤é¥æ©ö¸ê®Æ¡C¦ý³ÌªñµLªk¤U¸ü¡A½Ð«ü¥¿¡CÁÂÁ¡I

Sub saveCSVfmURL(selDate As String)
Dim st, nt, mond, dayd
Dim myURL, myURL2 As String
Dim oStream As Object           'ADODB.Stream
Dim WinHttpReq As Object            'XMLHTTP
Dim fileIdx As String
Dim folderLoc As String
Dim twPath As String
Dim twoPath As String
Dim cTw As String
Dim cTwo As String
Dim y1 As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False

fileIdx = selDate
folderLoc = Sheets("Download").Range("F2").Value

st = VBA.Left(fileIdx, 4) - 1911
nt = VBA.Right(fileIdx, 4)
dayd = VBA.Right(nt, 2)
mond = VBA.Left(nt, 2)

twPath = folderLoc & "\TW\"

If Len(Dir(twPath, vbDirectory)) = 0 Then
        MkDir twPath
End If

cTw = twPath & selDate & "_TW.csv"

myURL = "http://www.twse.com.tw/exchangeReport/MI_INDEX?response=csv&date=" & VBA.Left(fileIdx, 4) & mond & dayd & "&type=ALLBUT0999"

Debug.Print myURL

Set WinHttpReq = CreateObject("MSXML2.XMLHTTP")

With WinHttpReq
   '.Open "GET", myURL, False
    .send
    myURL = .responseText
End With

If myURL <> "" Then
Set oStream = CreateObject("ADODB.Stream")
With oStream
    .Open
    .Type = 1
    .Write WinHttpReq.responseBody
    fileIdx = twPath & selDate & "_TW.csv"
    On Error Resume Next
    Kill fileIdx
    On Error GoTo 0
    .SaveToFile fileIdx
    .Close
End With
End If
Set WinHttpReq = Nothing
Set oStream = Nothing

Dim removeSmallFile As Integer
removeSmallFile = ActiveSheet.Shapes("cBox_sFile").ControlFormat.Value
   
If removeSmallFile = 1 Then
    Call fileSizeCheck(twPath)
    Call fileSizeCheck(twoPath)
End If
  
    Range("A1").Select
   
    ActiveWorkbook.Save
    ActiveWorkbook.Close
  
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub


Sub fileSizeCheck(mySourcePath)
    Dim OFS As Object
    Dim mySource As Object
    Dim myFile As Object
    Set OFS = CreateObject("Scripting.FileSystemObject")
    Set mySource = OFS.getFolder(mySourcePath)
    On Error Resume Next
    For Each myFile In mySource.Files
        If myFile.Size < 10000 Then
            Kill myFile
        End If
    Next
End Sub

¦^´_ 1# karlho
myURL = "https://www.twse.com.tw/exchangeReport/MI_INDEX?response=csv&date=" & VBA.Left(fileIdx, 4) & mond & dayd & "&type=ALLBUT0999"

¥u­n­×¥¿¤@­Ó¦r

TOP

°O±o¬O OTCªº³Ìªñ§ï¦¨ https

¤W¥«ªº§ï¤F«Ü¤[¤F

TOP

        ÀR«ä¦Û¦b : ¤H¥Í¨S¦³©Ò¦³Åv¡A¥u¦³¥Í©Rªº¨Ï¥ÎÅv¡C
ªð¦^¦Cªí ¤W¤@¥DÃD