原先是使用
fd = ThisWorkbook.Path & "\"
fs = Dir(fd & "*.csv")
但是常常有需要臨時匯入的情況,後來修改之後...變成一次只能匯入一個檔案,
想情教各位老師!! 我應該要修改哪裡 ^^
資料匯集.rar (16.67 KB)
- Sub ex()
- Dim arr()
- Dim Filename As Variant
- Dim i As Integer
- fs = Application.GetOpenFilename("僅能匯入csv格式,*.csv", , "確定", , False)
- p = Range("G65536").End(xlUp).Row + 1
- With CreateObject("Microsoft.XMLHTTP")
- .Open "GET", fs, False
- .Send
- tt = .responsetext
- ss = Split(tt, vbCrLf)
- End With
- ReDim arr(0 To UBound(ss), 0 To 15)
- For i = 0 To UBound(ss)
- s1 = Split(ss(i), ",")
- For j = 0 To UBound(s1)
- arr(i, j) = s1(j)
- Next j
- Next i
- Cells(p, "a") = Replace(arr(5, 1), "'", "")
- Cells(p, "b") = Replace(Split(Cells(p, "a"), "-")(0), Mid(Split(Cells(p, "a"), "-")(0), 3, 5), "")
- Cells(p, "c") = Split(Cells(p, "a"), "-")(1)
- Cells(p, "G") = arr(3, 3)
- If arr(11, 7) = "Bef" Then
- Cells(p, "H") = "[Before]"
- Else
- Cells(p, "H") = "[After]"
- End If
- Cells(p, "I") = arr(11, 5)
- Cells(p, "J") = arr(11, 5)
- Cells(p, "K") = arr(20, 5)
- Cells(p, "R") = arr(21, 5)
- Cells(p, "S") = arr(22, 5)
- Cells(p, "T") = arr(23, 5)
- k = 20
- For i = 26 To 33
- For j = 1 To 3
- k = k + 1
- Cells(p, k) = arr(i, (j - 1) * 2 + 1)
- Next j
- Next i
- End Sub
複製代碼 |